Post back not working in Firefox for asp.net(C#) pages
Asked Answered
E

5

6

I have a problem with mozilla firefox.

I am developing a web site using asp.net language and I have a button in a form. when i clicked the button at onclick attributies i am calling a function and this funtion doing postback.

this scenerio is working chrome and internet exploerer. but it is not working at mozilla firefox. i am getting this error in console : TypeError: access to strict mode caller function is censored..

my sample button is :

<input id="Button1" type="button" onclick="sampleFunc('sample');" value="button" />

and my sample function is :

function sampleFunc(reqMessage)
{
  __doPostBack('', reqMessage);
}

I searched on internet. and many people have rhis problem but there is no any solution.

Do you have any solution about this bug (!)

EDIT 1: I have found a ticket on jquery web site. According to the ticked, thay fixed that bug. But i applied same solition but my bug is continue. :(

Enidenigma answered 18/12, 2014 at 11:23 Comment(8)
try sending the button id with the post, ie __doPostBack(ButtonID, reqMesage)..Margenemargent
are you using <asp:button or you are writing the bere HTML markup?Margenemargent
i am using hrml button. i mean <input type = "button" ...Enidenigma
somehow I would change it a server side control.. it is more robust in asp.net..Margenemargent
Is the sampleFunc function called first of all?Owain
yes @RaraituL . Firstly sample func is calling.Enidenigma
Using your browser's Developer Tools, search all included scripts for "use strict". Are there any occurrences?Sealskin
I have create a bug report about this.Matisse
E
3

Finaly i found the answer.

I am using alertfy javascript library for popup message. This Library is using "Use strict" expression.

And i deleted this expression from this library, Now there is no problem. My code is working on all browsers.

Enidenigma answered 14/1, 2015 at 15:13 Comment(2)
This saved me from getting fired. In my case I had to download a jquery 3.x CDN to reference it locally in my project and then remove all the instances of Use strict;.Armenta
The "Use strict" expression must be used in alertify javascript library. Actually, that expression must be used in all javascript file. It organizes the javascript file. I think, there is some unusual or error code is alertify js. Because of that reason we are getting an error. So, We have to remove that expression for now.Enidenigma
F
4

ASP.Net ScriptManager code walks up the call stack with "caller.callee" in __doPostBack to detect infinite recursion. That will fail on FireFox if any function in the call stack was parsed with "use strict" applied. The workaround is to have a function outside of the scope of "use strict" that calls setTimeout() to call a function that calls __doPostBack. setTimeout() gets you out of the call stack.

Friesen answered 26/4, 2016 at 14:26 Comment(1)
Found the solution here: https://mcmap.net/q/599597/-jqueryui-dialog-firefox-asp-net-access-to-strict-mode-caller-function-is-censored and it worked but I wanted to understand why this works so kept searching until I found your answer. Thanks for the explanation.Tonedeaf
E
3

Finaly i found the answer.

I am using alertfy javascript library for popup message. This Library is using "Use strict" expression.

And i deleted this expression from this library, Now there is no problem. My code is working on all browsers.

Enidenigma answered 14/1, 2015 at 15:13 Comment(2)
This saved me from getting fired. In my case I had to download a jquery 3.x CDN to reference it locally in my project and then remove all the instances of Use strict;.Armenta
The "Use strict" expression must be used in alertify javascript library. Actually, that expression must be used in all javascript file. It organizes the javascript file. I think, there is some unusual or error code is alertify js. Because of that reason we are getting an error. So, We have to remove that expression for now.Enidenigma
I
1

My advice is to keep javascript and Html separate ..instead of using inline call you can try this method

Note you must have jquery loaded for this to work.

eg:

<script>
$(document).ready(function()
{

     $(#Button1).click(function()
      {
        PostBack();

        });

});

</script>
    <input id="Button1" type="button" value="button" />
Intermarriage answered 18/12, 2014 at 11:47 Comment(0)
A
1

I have good news that the problem might be fixed in the latest Firefox and jQuery 3.5.1. I tested the reported scenario today plus other __doPostBack problematic scenarios related to the 'use strict' rule and all of them seem to work without any JS errors.

Do you still experience this issue with the latest jQuery 3.5.1 and latest Firefox 84.0.2?

Annalisaannalise answered 14/1, 2021 at 17:3 Comment(1)
Web UI JS frameworks enhanced a lot. I am not using PostBack anymore : )Enidenigma
A
0

This is a work around -

Add a server side button controller to your aspx page -

<asp:Button id="btn" runat="server" onclick="btn_click_event" ClientIDMode="static"/>

On your code behind page (aspx.cs) define the event method that will do the actual work after postback. Now make this button controller hidden.

<asp:Button id="btn" runat="server" onclick="btn_click_event"  ClientIDMode="static" style="display:none" />

Do not use Visible=false as it will just won't render the button at all.

Now change your javascript function to just invoke click on `btn'

function sampleFunc()
{
    $('#btn').click();
}

And call this function in your HTML input buttons onclick method -

<input id="Button1" type="button" onclick="sampleFunc();" value="button" />
Aftonag answered 11/1, 2015 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.