Reputation: 2738
__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";
}
}
Upvotes: 0
Views: 4220
Reputation: 165
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.
Upvotes: 0
Reputation: 2509
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.
Upvotes: 1