Loadpostdata of dynamically created controls in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • knknknkn
    New Member
    • Mar 2007
    • 10

    Loadpostdata of dynamically created controls in ASP.NET

    1. Can anyone explain ,when Load post data event of a webservercontro l executes ,if it is created in pageload instead of init?[asp.net,C#]

    2.My requirement was to create a textbox dynamically based on some contitions.so i created it in pageload.when the page is posted back(using a submit button) i am able to access user entered data in my dynamically created text box in submitbtn_click event.
    I didnot understand the reason ,why i am able to access user entered data in my dynamically created text box, when i am creating it in page load which occurs after Load post data event .[asp.net,C#]
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    hi knknknkn,

    Welcome to theScripts. You will find better responses to questionsd such as these in the various forums where the experts hang out (which you'll find on the Right Hand Side of the screen). I am moving this post to the .NET forum for you now....

    Comment

    • knknknkn
      New Member
      • Mar 2007
      • 10

      #3
      Originally posted by DeMan
      hi knknknkn,

      Welcome to theScripts. You will find better responses to questionsd such as these in the various forums where the experts hang out (which you'll find on the Right Hand Side of the screen). I am moving this post to the .NET forum for you now....

      ok thanks DeMan

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Code is executed line by line, so as long the textbox is created in the code before any event is executed and the users have an opportunity to fill in then it works. As the click event is executed and the textboxes exist when called there is no problem. If you are still interested in the finer details, this article may help:
        ASP.NET Page Life Cycle Overview

        Comment

        • knknknkn
          New Member
          • Mar 2007
          • 10

          #5
          thanks for ur response kenobewan,but i did not make out any thing of ur response.do u mean that ,the textbox which i created dynamically in pageload will cause the loadpostdata event of the page to be called again .i am working on
          .net1.1,c#.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by knknknkn
            thanks for ur response kenobewan,but i did not make out any thing of ur response.do u mean that ,the textbox which i created dynamically in pageload will cause the loadpostdata event of the page to be called again .i am working on
            .net1.1,c#.
            Hello there,

            When the user first visits your website the PageLoad() method is called.
            Here your textbox is dynamically created and is displayed in your user's web-browser.

            The user is then able to enter information into the textbox and submit the form.
            All of the values on the page are then sent to the server and the PageLoad() is called again. Since all of the values have been submitted you can access them in PageLoad or any other method in your web application.

            Once the PageLoad() happens, the event handler code for your submit button is called...rememb er that all of the information from the form (including the information in the textbox) has already been submitted to your web-application...t his is why you can access the user's information here.

            Does this help at all?

            -Frinny

            Comment

            • knknknkn
              New Member
              • Mar 2007
              • 10

              #7
              Hello Frinavale,in which stage does the valu of TEXTBOX.TEXT PROPERTY Set to the value entered by the user(I think it should happen in LOADPOSTDATA Event .but in my case ,before i created the textbox this event is over).
              But i am still able to access this value .so where or in which event is this text property of textbox being set.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by knknknkn
                Hello Frinavale,in which stage does the valu of TEXTBOX.TEXT PROPERTY Set to the value entered by the user(I think it should happen in LOADPOSTDATA Event .but in my case ,before i created the textbox this event is over).
                But i am still able to access this value .so where or in which event is this text property of textbox being set.
                Hi there!

                I'm just going to quickly review the page life cycle:
                =============== =============== =============== ============
                Page Request
                ASP.Net figures out if the page needs to be parsed/compiled or if there is a cached version of your website that can be sent back to the user without "Running" the page.

                Start
                The page properties Request and Response are set and it is determined whether the request is postback or not.

                ****Page Initialization
                Your controls are set

                Load
                The OnLoad() event method is called for your main page and all of its childern

                Validation
                The validation for each input control is performed. The IsValid property is set, indicating if the input was valid or not

                Postback Event
                The method that handles the event that caused the postback is executed.

                Rendering
                The viewSate is saved and the page is rendered and saved into an output stream in order to send it to the browser.

                Unload
                This happens after the page has been sent to the browser ...the Request and Response objects are destroyed ...basically clean up happens
                =============== =============== =============== ============

                During the Page Initialization stage the PreLoad() event handler is called to load the view state and set all of your controls....I believe your TextBox.Text value is set here.

                Cheers!

                -Frinny

                Comment

                • knknknkn
                  New Member
                  • Mar 2007
                  • 10

                  #9
                  i am creating my textbox dynamically in pageload which happens after the completion of view stateloading and post dataprocessing. In this situation the text box should never get a chance to involve in view stateloading and post dataprocessing. let me be more clear
                  =============== =============== =
                  pagelifecycle:
                  [ASP.NET 1.1]
                  i have added statically only one button and a label

                  1.First Request:
                  ----------------------------
                  1.page_init.-->(button,labe l)
                  2.loadviewstate
                  3.loadpostdata
                  4.pageload.-------->Here i am creating my TextBox.
                  {
                  tb=new TextBox();
                  this.FindContro l("Form1").Cont rols.Add(tb);
                  }
                  *
                  *
                  page_unload and sent to browser.

                  output in browser:
                  textbox appears along with button and label
                  ------------------------------------------------------------
                  page posted back to server.
                  ------------------------------------------------------------
                  *************** *************** *************** *************** *********
                  2.Second Request:
                  ------------------------------
                  1.page_init.--------->all statically added controls initialised(but ton,label)

                  2.loadviewstate---->setting view state of statically added controls

                  3.loadpostdata----->setting user entered values of initialized controls
                  (user entered values in browser)
                  Note:here in my case ,the textbox is not yet created,so there is no scope for setting its textproperty.

                  4.pageload.-------->Here i am creating my TextBox.
                  private void Page_Load(objec t sender, System.EventArg s e)
                  {
                  //put user code to initialize the page here
                  tb=new TextBox();
                  this.FindContro l("Form1").Cont rols.Add(tb);
                  }
                  ----------
                  Note:here in post back after page load event i am able to get user entered value which i am retrieving it in btn1 _click shown below.
                  *************** *************** *************** *************** *************** *************
                  my doubt is how text property of the text box is being set when loadpostdata event is completed before its creation.*************** *************** *************** *************** *************** ***************
                  -----------
                  private void Button1_Click(o bject sender, System.EventArg s e)
                  {
                  Label1.Text=tb. Text;

                  }

                  *
                  *

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Originally posted by knknknkn
                    i am creating my textbox dynamically in pageload which happens after the completion of view stateloading and post dataprocessing. In this situation the text box should never get a chance to involve in view stateloading and post dataprocessing. let me be more clear
                    =============== =============== =
                    pagelifecycle:
                    [ASP.NET 1.1]
                    i have added statically only one button and a label

                    1.First Request:
                    ----------------------------
                    1.page_init.-->(button,labe l)
                    2.loadviewstate
                    3.loadpostdata
                    4.pageload.-------->Here i am creating my TextBox.
                    {
                    tb=new TextBox();
                    this.FindContro l("Form1").Cont rols.Add(tb);
                    }
                    *
                    *
                    page_unload and sent to browser.

                    output in browser:
                    textbox appears along with button and label
                    ------------------------------------------------------------
                    page posted back to server.
                    ------------------------------------------------------------
                    *************** *************** *************** *************** *********
                    2.Second Request:
                    ------------------------------
                    1.page_init.--------->all statically added controls initialised(but ton,label)

                    2.loadviewstate---->setting view state of statically added controls

                    3.loadpostdata----->setting user entered values of initialized controls
                    (user entered values in browser)
                    Note:here in my case ,the textbox is not yet created,so there is no scope for setting its textproperty.

                    4.pageload.-------->Here i am creating my TextBox.
                    private void Page_Load(objec t sender, System.EventArg s e)
                    {
                    //put user code to initialize the page here
                    tb=new TextBox();
                    this.FindContro l("Form1").Cont rols.Add(tb);
                    }
                    ----------
                    Note:here in post back after page load event i am able to get user entered value which i am retrieving it in btn1 _click shown below.
                    *************** *************** *************** *************** *************** *************
                    my doubt is how text property of the text box is being set when loadpostdata event is completed before its creation.*************** *************** *************** *************** *************** ***************
                    -----------
                    private void Button1_Click(o bject sender, System.EventArg s e)
                    {
                    Label1.Text=tb. Text;

                    }

                    *
                    *
                    The web server takes all the input submitted to it and puts it into a Request Object which ASP.NET takes and sorts out before any processing happens. Your Textbox that was created last time and all the data it contains is stored in the Request object....and ASP.NET loads it into its Request property.

                    ASP.NET also uses a Cached version of the page to serve any requests that happen after the very first request is made. This means that even though you've created your Textbox in your PageLoad() it can still be initialized.

                    Comment

                    • knknknkn
                      New Member
                      • Mar 2007
                      • 10

                      #11
                      Hello Frinavale

                      if i assign my textbox id as "t1",then can u let me know how can i access it or its entered value form requestobject on post back

                      Comment

                      Working...