简体   繁体   中英

__doPostBack not working in chrome and safari

__doPostBack() function works in FF and IE,but not working in safari and chrome. I have following code in my asp.net c# application

ASPX Code


<a href="www.myAddress.com/abcdef.html" onclick="javascript:SetPosition(); ">Click here</a>

JS Function


function SetPosition() {
        __doPostBack('ahref', 'link');
}

CS Code


protected void Page_Load(object sender, EventArgs e)
{
            if (!IsPostBack)
            {
                // Other code is here
            }
            else if (Request.Params["__EVENTARGUMENT"] != null && Convert.ToString(Request.Params["__EVENTARGUMENT"]).Trim() == "link")
            {
                Session["TopPossition"] = "9999";
            }
}

I believe you need to pass the server control id as the EventTarget and not the client id when you use __doPostBack call. Try changing the __doPostBack call as so...

<a id="someclientid" name="someuniqueid" href="javascript:void(0);" onclick="__doPostBack('someuniqueid', '');">val</a>

By default, controls use __doPostBack to do the postback to the server. __doPostBack takes the UniqueID of the control (or in HTML, the name property of the HTML element). The second parameter is the name of the command to fire.

The onclick event handler needs to supress the links default behavior to navigate to what's specified in the href attribute.

It should be like this:

<a href="#" onclick="SetPosition(); return false " >Click here</a>

you can provide redirection in SetPosition() if required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM