简体   繁体   English

__doPostBack在chrome和safari中不起作用

[英]__doPostBack not working in chrome and safari

__doPostBack() function works in FF and IE,but not working in safari and chrome. __doPostBack()函数适用于FF和IE,但不适用于Safari和Chrome。 I have following code in my asp.net c# application 我的asp.net c#应用程序中有以下代码

ASPX Code ASPX代码


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

JS Function JS功能


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

CS Code CS代码


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. 我相信您在使用__doPostBack调用时需要将服务器控件ID作为EventTarget而不是客户端ID传递。 Try changing the __doPostBack call as so... 尝试按以下方式更改__doPostBack调用:

<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进行回发到服务器。 __doPostBack takes the UniqueID of the control (or in HTML, the name property of the HTML element). __doPostBack获取控件的UniqueID(或在HTML中,HTML元素的name属性)。 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. onclick事件处理程序需要禁止链接的默认行为,以导航到href属性中指定的内容。

It should be like this: 应该是这样的:

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

you can provide redirection in SetPosition() if required. 您可以根据需要在SetPosition()中提供重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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