ASP.NET Button not redirecting on IE
Currently I have a button which on client click, runs a jquery function that changes the text on a (hidden to the user) label, and then clicks a second (also hidden to the user) button. This second button then runs an ASP.NET function whose last command is to redirect to a second page. The reason I needed to do this, is because I store the value of the label (which 开发者_如何转开发is dynamically assigned according to a database) into a session variable BEFORE redirecting to the second page.
This method works perfectly on Chrome and Firefox. Nevertheless, it doesn't seem to be redirecting in IE. It does, however, store the session variable (i.e. the sub routine that handles the hidden button's click event IS called).
Does anyone know why this can be?
Thank you very much for your help! I sincerely appreciate any input.
Edit: I've tried clicking the hidden button myself, and it works fine, so it is definitely something with the postback from the first button interfering with the subroutine called from the second one.
Why are you redirecting from the ASP.net function? Are you using jQuery AJAX to execute that function? I think your best option is call a jQuery Ajax function which stores your value in session and then (again in your javascript code) do the redirect:
document.location = 'your_new_url.aspx'
Hope that helps.
Try this:
In your javascript code:
$.ajax({
type: "POST",
url: "yourPageName.aspx/SetSession",
data: "{value: '" + the_session_value_you_want_to_store + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if(response.d.length==0) {
//all was OK, redirect
document.location = 'your_new_url.aspx';
} else {
//mmmm some error
alert(response.d);
}
},
error: function(msg) {
alert(msg);
}
});
In your VB.net code:
<WebMethod()> _
Public Shared Function SetSession(ByVal value As String) As String
Dim output As String = String.Empty
Try
HttpContext.Current.Session("your_session_variable_name") = value
Catch ex As Exception
output = ex.ToString()
End Try
Return output
End Function
If you can't see the attribute when writing your server code, add this Imports to your page: Imports System.Web.Services
Hope that helps.
精彩评论