call __doPostBack from javascript method not working as expected

S

SteveSu

Hi!
I want to make a postback when the user hits the escape-button on the
keyboard and redirect the user to another page. But the
response.redirect does not work for me in this "context".
I´m trying to do like this:


<body onkeydown="MyRedirect()">


function MyRedirect()
{
if(event.keyCode == 27)
{
__doPostBack('', 'myRedirect');
}


}


--
The doPostBack method is autogenerated by .net and look like this in
..net 2.0.
--

function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}


}


--

This will trigger a postback.
In page_load I´m doing like this:


Private Sub Page_Load(...) Handles Me.Load
If Page.IsPostBack Then
If Request.Form("__EVENTARGUMENT") = "myRedirect" Then
response.redirect("anotherPage.aspx")
End If
End If
End Sub


Nothing happens when executing response.redirect. Why is that?


Thanks in advance
/ Steve
 
G

George

Response.Reddirect is simply not executed.
Most likely IsPostBack return false.
Leve the code like that
If Request.Form("__EVENTARGUMENT") = "myRedirect" Then
response.redirect("anotherPage.aspx")
End If
you do not need to check on PostBack

George.


Hi!
I want to make a postback when the user hits the escape-button on the
keyboard and redirect the user to another page. But the
response.redirect does not work for me in this "context".
I´m trying to do like this:


<body onkeydown="MyRedirect()">


function MyRedirect()
{
if(event.keyCode == 27)
{
__doPostBack('', 'myRedirect');
}


}


--
The doPostBack method is autogenerated by .net and look like this in
.net 2.0.
--

function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}


}


--

This will trigger a postback.
In page_load I´m doing like this:


Private Sub Page_Load(...) Handles Me.Load
If Page.IsPostBack Then
If Request.Form("__EVENTARGUMENT") = "myRedirect" Then
response.redirect("anotherPage.aspx")
End If
End If
End Sub


Nothing happens when executing response.redirect. Why is that?


Thanks in advance
/ Steve
 
S

SteveSu

Thanks for the reply.
This is not the case. I have steped through the code in the debugger
som I know that the response.redirect line is executed.
The strange thing is that it does not seems to be an ordinary postback,
cause if I for example change the text-value for a label, the value is
not changed when the page is shown again.
I have tested the same thing for a LinkLabel. First I add a linklabel
to the page. In the event for the linklabel I have added a
response.redirect. This works fine if I click on the link, but if I
call it from a javascript method like __doPostBack('LinkButton1', '')
the event is called but no response.redirect is done. What is the
difference between this scenarios?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top