Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. PostBackUrl

PostBackUrl

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascripttutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Munteanu Ciprian
    wrote on last edited by
    #1

    Here's my problem: I have a button and when I click it I want to open a new page. I know that I can do this thing very easy by setting the PostBackUrl property of the button. But here's what I want to do: on my page I have a textbox and, for example when I press the button I want to test the text from the TextBox and if it's ok I want to show the new page; if not I want to display a message. I want to do that using c# language, and not JavaScript. I've tried this: protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "something") Button1.PostBackUrl = "NewPage.aspx"; else .................... } Ok, everithing is fine until now. But when I press the button, assuming that in my textbox I've written "something", the NewPage isn't displayed. My current page is loaded again and when I press the button again then NewPage.aspx is displayed. And I don't know why this is happening. Can anyone help me please?

    OriginalGriffO M 2 Replies Last reply
    0
    • M Munteanu Ciprian

      Here's my problem: I have a button and when I click it I want to open a new page. I know that I can do this thing very easy by setting the PostBackUrl property of the button. But here's what I want to do: on my page I have a textbox and, for example when I press the button I want to test the text from the TextBox and if it's ok I want to show the new page; if not I want to display a message. I want to do that using c# language, and not JavaScript. I've tried this: protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "something") Button1.PostBackUrl = "NewPage.aspx"; else .................... } Ok, everithing is fine until now. But when I press the button, assuming that in my textbox I've written "something", the NewPage isn't displayed. My current page is loaded again and when I press the button again then NewPage.aspx is displayed. And I don't know why this is happening. Can anyone help me please?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Try:

      protected void Button1_Click(object sender, EventArgs e)
      {
      if (TextBox1.Text == "something")
      {
      Response.Redirect("NewPage.aspx");
      }
      else
      {
      ....................
      }
      }

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Try:

        protected void Button1_Click(object sender, EventArgs e)
        {
        if (TextBox1.Text == "something")
        {
        Response.Redirect("NewPage.aspx");
        }
        else
        {
        ....................
        }
        }

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

        M Offline
        M Offline
        Mark Graham
        wrote on last edited by
        #3

        I think he wants to "Postback" to a new page and not re-direct to a new page.

        Mark Graham (MCP) blogging about Design Patterns, C#, Asp.Net, CSS, Javascript and Ajax at: DESIGN CODE TEST[^]

        1 Reply Last reply
        0
        • M Munteanu Ciprian

          Here's my problem: I have a button and when I click it I want to open a new page. I know that I can do this thing very easy by setting the PostBackUrl property of the button. But here's what I want to do: on my page I have a textbox and, for example when I press the button I want to test the text from the TextBox and if it's ok I want to show the new page; if not I want to display a message. I want to do that using c# language, and not JavaScript. I've tried this: protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "something") Button1.PostBackUrl = "NewPage.aspx"; else .................... } Ok, everithing is fine until now. But when I press the button, assuming that in my textbox I've written "something", the NewPage isn't displayed. My current page is loaded again and when I press the button again then NewPage.aspx is displayed. And I don't know why this is happening. Can anyone help me please?

          M Offline
          M Offline
          Mark Graham
          wrote on last edited by
          #4

          The Postback url defaults to the current page and this is where your first click will return to, because, at this first click point your browser doesn't know to postback to NewPage.aspx. Only on the second click (after you've set Button1.PostBackUrl = "NewPage.aspx") will you get postback to the new page. IF YOU NEED TO POSTBACK TO A DIFFERENT PAGE THEN.... you can't avoid using javascript. Setting PostBackUrl on the server won't affect the current request (your first click). IF YOU'RE NOT REALLY CONCERNED WITH POSTBACK THEN.... do what the other guys suggested and replace the Button1.PostBackUrl = "NewPage.aspx" with the ReDirect, or Server.Transfer("NewPage.aspx"); code.

          Mark Graham (MCP) blogging about Design Patterns, C#, Asp.Net, CSS, Javascript and Ajax at: DESIGN CODE TEST[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups