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. C#/ASP Updating ASP:Label Problem

C#/ASP Updating ASP:Label Problem

Scheduled Pinned Locked Moved ASP.NET
csharphtmldatabasehelptutorial
9 Posts 2 Posters 1 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.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    Can someone provide an example where you get a value from the query string, use it somehow, and update the values of some form fields? Basically, I want to have a URL ( .../page1.aspx?ID=345 ) that specifies some value. Then, I want to extract that value and display it in an ASP field. I can extract the value and display it using Response.Write, but can't seem to make it update the ASP:Label. :confused: ======= page1.aspx ======== <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %> Sample

    <% // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This does not work. SetValue(Request.QueryString["ID"]); // This does not work. Message.Text = Request.QueryString["ID"]; %> void SetValue(String sValue) { Message.Text = "Received " + sValue; } =========================== Thanks for any pointers. --G Modified: Forgot to check the box.

    M 1 Reply Last reply
    0
    • G Glenn E Lanier II

      Can someone provide an example where you get a value from the query string, use it somehow, and update the values of some form fields? Basically, I want to have a URL ( .../page1.aspx?ID=345 ) that specifies some value. Then, I want to extract that value and display it in an ASP field. I can extract the value and display it using Response.Write, but can't seem to make it update the ASP:Label. :confused: ======= page1.aspx ======== <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %> Sample

      <% // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This does not work. SetValue(Request.QueryString["ID"]); // This does not work. Message.Text = Request.QueryString["ID"]; %> void SetValue(String sValue) { Message.Text = "Received " + sValue; } =========================== Thanks for any pointers. --G Modified: Forgot to check the box.

      M Offline
      M Offline
      Marcie Jones
      wrote on last edited by
      #2

      You need to check it for nulls, and cast/convert it to a string (or an int). Marcie CP Blog[^]

      G 1 Reply Last reply
      0
      • M Marcie Jones

        You need to check it for nulls, and cast/convert it to a string (or an int). Marcie CP Blog[^]

        G Offline
        G Offline
        Glenn E Lanier II
        wrote on last edited by
        #3

        I know my example didn't account for all error conditions, but for examples sake, assuming a value is passed it, I'd like to update the ASP:Label called Message. I modified the code a little from what is above: <% // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This does not work. Message.Text = "Some VALID string"; %> and can't get the Message.Text line to display.

        M 1 Reply Last reply
        0
        • G Glenn E Lanier II

          I know my example didn't account for all error conditions, but for examples sake, assuming a value is passed it, I'd like to update the ASP:Label called Message. I modified the code a little from what is above: <% // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This does not work. Message.Text = "Some VALID string"; %> and can't get the Message.Text line to display.

          M Offline
          M Offline
          Marcie Jones
          wrote on last edited by
          #4

          Don't specify a Text property in the [asp:TextBox] declaration since I think that overrides whatever happens in code. Otherwise, this should work: Message.Text = (string) Request.QueryString["ID"].ToString(); Marcie CP Blog[^]

          G 1 Reply Last reply
          0
          • M Marcie Jones

            Don't specify a Text property in the [asp:TextBox] declaration since I think that overrides whatever happens in code. Otherwise, this should work: Message.Text = (string) Request.QueryString["ID"].ToString(); Marcie CP Blog[^]

            G Offline
            G Offline
            Glenn E Lanier II
            wrote on last edited by
            #5

            Marcie, Thanks for the example, but it didn't work for me. Changing my code (in the <% %>) to: // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This statement does not work. Message.Text = (string) Request.QueryString["ID"].ToString(); generates the following output: ==== Response Write: 342 ====

            M 1 Reply Last reply
            0
            • G Glenn E Lanier II

              Marcie, Thanks for the example, but it didn't work for me. Changing my code (in the <% %>) to: // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This statement does not work. Message.Text = (string) Request.QueryString["ID"].ToString(); generates the following output: ==== Response Write: 342 ====

              M Offline
              M Offline
              Marcie Jones
              wrote on last edited by
              #6

              Weird. Can you paste in the current ASPX portion of your code again? Marcie CP Blog[^]

              G 1 Reply Last reply
              0
              • M Marcie Jones

                Weird. Can you paste in the current ASPX portion of your code again? Marcie CP Blog[^]

                G Offline
                G Offline
                Glenn E Lanier II
                wrote on last edited by
                #7

                Sure, no problem. I access this at http://localhost/page.aspx?ID=234 ======== <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true" %> Sample <% // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This statement does not work. Message.Text = (string) Request.QueryString["ID"].ToString(); %> =============

                M 1 Reply Last reply
                0
                • G Glenn E Lanier II

                  Sure, no problem. I access this at http://localhost/page.aspx?ID=234 ======== <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true" %> Sample <% // This statement works. Response.Write("Response Write: " + Request.QueryString["ID"]); // This statement does not work. Message.Text = (string) Request.QueryString["ID"].ToString(); %> =============

                  M Offline
                  M Offline
                  Marcie Jones
                  wrote on last edited by
                  #8

                  Ah, I just noticed that that code is not inside an event. Put it into page_load and you should be set. Inline code (not inside an event) still works in ASP.NET, but it's not a good idea. Marcie CP Blog[^]

                  G 1 Reply Last reply
                  0
                  • M Marcie Jones

                    Ah, I just noticed that that code is not inside an event. Put it into page_load and you should be set. Inline code (not inside an event) still works in ASP.NET, but it's not a good idea. Marcie CP Blog[^]

                    G Offline
                    G Offline
                    Glenn E Lanier II
                    wrote on last edited by
                    #9

                    Marcie, Thanks so much. It is working now -- my new code is below. --G ===== <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true" %> Sample Passed Value:
                    protected void Page_Load(Object Source, EventArgs E) { // This works now! Message.Text = (string) Request.QueryString["ID"].ToString(); } =====

                    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