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

我只是一个虾纸丫 提交于 2019-12-12 11:33:54

问题


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. :(


回答1:


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.




回答2:


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.




回答3:


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" />



回答4:


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" />


来源:https://stackoverflow.com/questions/27545418/post-back-not-working-in-firefox-for-asp-netc-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!