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. ClientID messes with my textbox - please help

ClientID messes with my textbox - please help

Scheduled Pinned Locked Moved ASP.NET
questionc++comtoolshelp
4 Posts 2 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.
  • A Offline
    A Offline
    Axonn Echysttas
    wrote on last edited by
    #1

    Hi everybody. Does anybody even IMAGINE why writing this in a RegisterStartupScript block would cause my textbox to lose its value upon postback???

    Page.ClientScript.RegisterStartupScript(GetType(),"document.getElementById('" + txtp.ClientID + "').value; "...... etc
    txtp.Text = "-1";

    Let me say that one more time. I am reffering to the ClientID of "txtp" in a RegisterStartupScript. I merely take the value from it, that's all. And when the page retuns, txtp always has its default value, the one I populate in it, see the next line, when I set -1. But if I comment out that line with the .ClientID, then when the pages posts back, after I repopulate, even if I set -1 to the textbox, I DO GET THE CORRECT number in it, which was entered client-side, before the user presses the submit button. With .Client ID line uncommented: 1. Load dynamic user control in which txtp is. 2. Set -1, register startup script 3. User writes 2 in the textbox 4. Submit 5. Value in textbox is -1. WRONG With .Client ID line commented: 1. Load dynamic user control in which txtp is. 2. Set -1, register startup script 3. User writes 2 in the textbox 4. Submit 5. Value in textbox is 2. CORRECT Somebody please help me out here....... I'm way over my head, I don't understand a bit of what is happening, even though I have studied the lifetime of the page and I am loading the control dinamically at the master's page Init. But even if I messed something up in the lifetime, THIS STILL DOESN'T explain why a silly .Client ID messes everything up! Weird!

    -= E C H Y S T T A S =- The Greater Mind Balance Blending C++ with COM ^ Have a break on my website! Spread the word? Please?

    A 1 Reply Last reply
    0
    • A Axonn Echysttas

      Hi everybody. Does anybody even IMAGINE why writing this in a RegisterStartupScript block would cause my textbox to lose its value upon postback???

      Page.ClientScript.RegisterStartupScript(GetType(),"document.getElementById('" + txtp.ClientID + "').value; "...... etc
      txtp.Text = "-1";

      Let me say that one more time. I am reffering to the ClientID of "txtp" in a RegisterStartupScript. I merely take the value from it, that's all. And when the page retuns, txtp always has its default value, the one I populate in it, see the next line, when I set -1. But if I comment out that line with the .ClientID, then when the pages posts back, after I repopulate, even if I set -1 to the textbox, I DO GET THE CORRECT number in it, which was entered client-side, before the user presses the submit button. With .Client ID line uncommented: 1. Load dynamic user control in which txtp is. 2. Set -1, register startup script 3. User writes 2 in the textbox 4. Submit 5. Value in textbox is -1. WRONG With .Client ID line commented: 1. Load dynamic user control in which txtp is. 2. Set -1, register startup script 3. User writes 2 in the textbox 4. Submit 5. Value in textbox is 2. CORRECT Somebody please help me out here....... I'm way over my head, I don't understand a bit of what is happening, even though I have studied the lifetime of the page and I am loading the control dinamically at the master's page Init. But even if I messed something up in the lifetime, THIS STILL DOESN'T explain why a silly .Client ID messes everything up! Weird!

      -= E C H Y S T T A S =- The Greater Mind Balance Blending C++ with COM ^ Have a break on my website! Spread the word? Please?

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Are you sure of this. I did this myself

      this.ClientScript.RegisterStartupScript(typeof(Page),"scriptblock", "var x = document.getElementById('" + txtp.ClientID + "').value; ");
      txtp.Text = "-1";

      and found 2 on txtp.Text when form is posted back. I think the problem is every time you post back the form it resets the txtp.Text to -1 as you wrote this in Page_Load event I think. So please write If(IsPostBack)return; at the beginning, I think it will work properly.. :rose::rose:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      A 1 Reply Last reply
      0
      • A Abhishek Sur

        Are you sure of this. I did this myself

        this.ClientScript.RegisterStartupScript(typeof(Page),"scriptblock", "var x = document.getElementById('" + txtp.ClientID + "').value; ");
        txtp.Text = "-1";

        and found 2 on txtp.Text when form is posted back. I think the problem is every time you post back the form it resets the txtp.Text to -1 as you wrote this in Page_Load event I think. So please write If(IsPostBack)return; at the beginning, I think it will work properly.. :rose::rose:

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        A Offline
        A Offline
        Axonn Echysttas
        wrote on last edited by
        #3

        Hi and thanks for answering Abhishek! No, this is not an IsPostBack problem. I'm not a beginner. Simply uncommenting that line will make the value reach the server again! That's the weird thing. And it works for you perhaps because you don't have that textbox in a dinamically created User Control. What I'm wondering is WHY EXACTLY uncommenting that shitty line makes everything work! I can't believe it!

        -= E C H Y S T T A S =- The Greater Mind Balance Blending C++ with COM ^ Have a break on my website! Spread the word? Please?

        A 1 Reply Last reply
        0
        • A Axonn Echysttas

          Hi and thanks for answering Abhishek! No, this is not an IsPostBack problem. I'm not a beginner. Simply uncommenting that line will make the value reach the server again! That's the weird thing. And it works for you perhaps because you don't have that textbox in a dinamically created User Control. What I'm wondering is WHY EXACTLY uncommenting that shitty line makes everything work! I can't believe it!

          -= E C H Y S T T A S =- The Greater Mind Balance Blending C++ with COM ^ Have a break on my website! Spread the word? Please?

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          Ya.. Is it so.. This is really weird. Love to see the exact scenario. If possible can you share the code with me. We can also place a bug report to Microsoft about that if it really happens... :rose::rose:

          Abhishek Sur


          My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

          **Don't forget to click "Good Answer" if you like to.

          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