call __doPostBack from javascript method not working as expected

Discussion in 'ASP .Net' started by SteveSu, Nov 7, 2005.

  1. SteveSu

    SteveSu Guest

    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
     
    SteveSu, Nov 7, 2005
    #1
    1. Advertising

  2. SteveSu

    George Guest

    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.


    "SteveSu" <> wrote in message news:...
    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
     
    George, Nov 7, 2005
    #2
    1. Advertising

  3. SteveSu

    SteveSu Guest

    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?


    George wrote:
    > 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.
    >
    >
    > "SteveSu" <> wrote in message news:...
    > 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
     
    SteveSu, Nov 8, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QUpQ?=

    __doPostBack manual call

    =?Utf-8?B?QUpQ?=, Aug 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,050
    =?Utf-8?B?QUpQ?=
    Aug 20, 2004
  2. =?Utf-8?B?Q2xhcw==?=
    Replies:
    0
    Views:
    1,510
    =?Utf-8?B?Q2xhcw==?=
    Nov 10, 2005
  3. Nathan Sokalski
    Replies:
    1
    Views:
    908
    Gregory A. Beamer
    Jan 11, 2010
  4. Mike Owen

    Javascript error is stopping __doPostBack working

    Mike Owen, Jun 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    488
    Mike Owen
    Jun 16, 2004
  5. Nathan Sokalski
    Replies:
    1
    Views:
    852
    Gregory A. Beamer
    Jan 11, 2010
Loading...

Share This Page