Accessing Control value

Last post 08-03-2007 2:26 AM by Amanda Wang - MSFT. 5 replies.

Sort Posts:

  • Accessing Control value

    08-01-2007, 11:16 PM
    • Member
      436 point Member
    • asppick
    • Member since 02-27-2004, 4:00 AM
    • Posts 457

     Hi,

    I am using Master Page in my project.

    In the content page (First.aspx) I placed a txt control called 'txtID'

    In the First.aspx button click event (PostBackURL=Second.aspx) I am calling Second.aspx

    In Second.aspx I am trying to access txtID value.

    So, I wrote Request.Form("txtID") in Second.aspx page_load event.

    Problem is I am unable to get txtID value with Request.Form("txtID")

    I need to write Request.Form("ctl100$ContentPlaceHolder1$txtID") to get the value.

    Why I need to append "ctl100$ContentPlaceHolder1$" to "txtID" to get the value?

    Thanks

     

  • Re: Accessing Control value

    08-01-2007, 11:25 PM
    • Contributor
      3,859 point Contributor
    • rojay12
    • Member since 04-03-2006, 10:43 PM
    • Sacramento, CA
    • Posts 703
    Jared Roberts
    Lead Application Developer
  • Re: Accessing Control value

    08-01-2007, 11:26 PM
    • Contributor
      3,859 point Contributor
    • rojay12
    • Member since 04-03-2006, 10:43 PM
    • Sacramento, CA
    • Posts 703

    or this...

    http://www.beansoftware.com/ASP.NET-Tutorials/Cross-Page-Posting.aspx specifically IsCrossPagePostBack Property.

    Jared Roberts
    Lead Application Developer
  • Re: Accessing Control value

    08-02-2007, 9:57 AM
    • Member
      436 point Member
    • asppick
    • Member since 02-27-2004, 4:00 AM
    • Posts 457

    Hi Roberts,

    Thanks for the Links.

    I just want to know, why I need to append "ctl100$contentplaceholder1", is there any specific reason for that?

    Thanks

  • Re: Accessing Control value

    08-02-2007, 11:46 PM
    • Contributor
      3,859 point Contributor
    • rojay12
    • Member since 04-03-2006, 10:43 PM
    • Sacramento, CA
    • Posts 703

     it has something to with what the uniqueid of the control is set to durning the page_init method.  As an alternative you can use the CType(PreviousPage.FindControl("txtID"), TextBox).Text.

    Jared Roberts
    Lead Application Developer
  • Re: Accessing Control value

    08-03-2007, 2:26 AM
    Answer

    Hi,

    Both the MasterPage and Content controls are naming containers. The key to using FindControl is to invoke the method on the correct container, because FindControl doesn’t recursively traverse the entire hierarchy of controls. FindControl only searches inside the current naming container.

    A naming container also mangles its children’s ClientID property. Mangling ensures all ClientID properties are unique on a page. For instance, the ID for our Label control is “Label1”, but the ClientID of the Label is “ctl00_ContentPlaceHolder1_Label1”. Each level of naming container prepends it’s ID to the control (the MasterPage control ID in this form is ctl00).

     

    Hope it helps. 

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (6 items)