Yes, you would better place your code to Page_Init event.

And you should reading some articles about Page life circle.

On Jun 7, 12:08 am, Cerebrus <[email protected]> wrote:
> Dynamically created controls need to be *recreated* upon postback and
> any eventhandlers need to be reattached. Only then will their
> associated events fire.
>
> On Jun 5, 3:56 pm, Rao <[email protected]> wrote:
>
>
>
>
>
> > Hi,
>
> > I am trying to create a tree structure based on an XML. For each row,
> > I need to add couple of text boxes and a button for which I am using
> > HTML controls, which i am embedding dynamically as shown below. After
> > postback i am losing the values of the text box controls. How can I
> > retrieve the values of my text boxes after the post back operation. I
> > have added the runat=server option as well.
>
> > Also, please suggest if there is a better way to accomplish what i am
> > trying to do.
>
> > Regards,
> > Rao
>
> >     protected void Page_Load(object sender, EventArgs e)
> >     {
> >         if (!Page.IsPostBack)
> >         {
> >             int num = 0;
> >             // Add the root node
> >             TreeNode rootNode = new TreeNode("ROOT");
> >             // This is to prevent the postback operation
> >             rootNode.SelectAction = TreeNodeSelectAction.None;
>
> >             TreeView1.Nodes.Add(rootNode);
>
> >             TreeNode childNode = new TreeNode();
> >             StringBuilder nodeText =  new StringBuilder();
> >             // This is to prevent the postback operation when clicking
> > the name
> >             childNode.SelectAction = TreeNodeSelectAction.None;
> >             nodeText.Append("CHILD...TextBox1:");
> >             nodeText.Append(@"<input type='Text' id='CPU0' value='000'
> > runat='server' >");
> >             nodeText.Append(@"<input type='button' id='btn0'
> > value='Submit'  onclick='javascript:__doPostBack(\"btnAsp\",\"0\");'
> > runat='server' >");
> >             childNode.Text = nodeText.ToString();
> >             nodeTest.ChildNodes.Add(childNode);
> >         }
>
> >         if (Request.Form["__EVENTTARGET"] != null && Request.Form
> > ["__EVENTTARGET"] == "btnAsp")
> >         {
> >             btnAsp_Click(null, null);
> >         }
> >     }

Reply via email to