do postback then re-direct to a page
I'm trying to do a javascript p开发者_开发知识库ostback and then re-direct to a different page but it keeps posting back to the current page
Here's my code
$(this).prepend('<a class="booknow2 sidelink sidelinkNew" href="javascript:__doPostBack(\'SetSess\',\'\')"><img src="../../images1/button/leftEdge.png" width="4" height="35" style="float:left; margin:0; padding:0;" alt="book now" /><img src="../../images1/button/rightEdge.png" width="4" height="35" style="float:right; margin:0; padding:0;" alt="book now" /><span>Check availability »</span></a>');
And here's my SetSess
postback command
Sub SetSess()
Session("TenHolStDateNewCheck") = "%"
response.redirect("searchresults/default.aspx")
End Sub
Anyone got any ideas?
Thanks
Jamie
__doPostBack the first parameter populates the __EVENTTARGET parameter... I could be wrong, but I wasn't aware that it automatically invoked methods. I think you have to do that yourself by doing in Load event:
if (request.Form["__EVENTTARGET"] = "SetSess") Then
SetSess()
End if
HTH.
You need to have a hidden button link so the page product the permission to accept this post back
<asp:LinkButton ID="LinkButton1" runat="server"
onclick="LinkButton1_Click" style="display:none;"></asp:LinkButton>
Then you can call your post back.
__doPostBack('<%=LinkButton1.ClientID%>','');
and your code be something like that.
$(this).prepend('<a class="booknow2 sidelink sidelinkNew"
href="javascript:__doPostBack(\'<%=LinkButton1.ClientID%>\',\'\')">
<img src="../../images1/button/leftEdge.png" width="4" height="35"
style="float:left; margin:0; padding:0;" alt="book now" /><img src="../../images1/button/rightEdge.png"
width="4" height="35" style="float:right; margin:0; padding:0;"
alt="book now" /><span>Check availability »</span></a>');
... and the function on code behind
protected void LinkButton1_Click(object sender, EventArgs e)
{
// Here the work and the redirect of you
}
Hope this work.
I used the jquery ajax function to call a page which set the session and then re-directed
Thanks for the help though
精彩评论