CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2010
    Posts
    3

    question about response.write/redirect

    how can i use these two commands together when i try it it works but the redirect activates before i can see my write. for example when i click my update button inside the code i would put all the stuff i want to send to a database, but if an error occurs i want to reply with a message then redirect after the user clicks ok on that pop-up. anyways heres the code im using for the .write .redirect:

    Response.Write("<script>alert('Update Unsuccessful');</script>");
    Response.Redirect("Page.aspx");

    ill have this in an if statement checking for problems if something comes up i want the user to know what they did wrong then it redirects them to the same page.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: question about response.write/redirect

    What is Response?
    What is Write?
    What is Redirect?
    What is <script>?
    What is the type of application you have the problems with?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2010
    Posts
    3

    Re: question about response.write/redirect

    uhh well its a like a commerical web site that stores and updates information from a database. the

    Response.Write("<script>alert('Update Unsuccessful');</script>");
    creates a pop-up icon with an ok button and a message saying update unsuccessful. this occurs when submit button is clicked

    Response.Redirect("Page.aspx");
    redirects you to another page in this case the file i am working on is Page.aspx so what i want to happen is when you click submit and get and error how would you create a pop-up letting the user know of the error then refresh the page to clear fields. i cant use MessageBox.Show because my hosting website doesn't support it.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: question about response.write/redirect

    Well, it sounds that your code is NOT a Visual C++. Is it?
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2010
    Posts
    3

    Re: question about response.write/redirect

    its c#

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: question about response.write/redirect

    Then why do you ask in C++ Forum?
    Ask it here!
    Victor Nijegorodov

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: question about response.write/redirect

    Besides, I have an impression that the question is more about HTTP stuff rather than C++ or C#. It seems to me, that Redirect has something to do with header, while script is something to be executed at loading. What I'm trying to say is that Page.aspx should implement the said alert, otherwise redirection must be done in the script, by re-assigning location for example.
    Best regards,
    Igor

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: question about response.write/redirect

    Quote Originally Posted by zezebox
    how can i use these two commands together when i try it it works but the redirect activates before i can see my write.
    Response.Write("<script>alert('Update Unsuccessful');</script>");
    Response.Redirect("Page.aspx");
    You're wrong. Both happens. Because you are redirecting to another page, that is why you don't see your written text. Why navigate away from the page in the first place?

    Set up proper error handling to ensure validity of your data first, then, only once everything is valid, redirect to where you want to. This is basic common exception handling.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured