Posted: 6/7/2011
I have a link button on my webpage on click of link button i am calling AddPanel() method
My Addpanel() method :-
public void addpanel() {
panel1.Width = 450; panel1.GroupingText = "Add your Professional Info"; //panel1.Location = new Point(10, 10); panel1.Wrap = true; panel1.CssClass = "pnl"; //creating lables Label lblcname = new Label(); Label lbltimeperiod = new Label(); Label lblpos = new Label(); Label lbldiscription = new Label(); lblcname.Text = "Company Name :"; lbltimeperiod.Text = "Time Period :" + " "; lblpos.Text = "Position :" + " "; lbldiscription.Text = "Discription :" + " "; //creating textbox txtcname.CssClass = "txtbox"; txtyear.Width = 30; txtyear1.Width = 30; txtpos.CssClass = "txtbox"; txtdisc.CssClass = "txtbox"; txtdisc.TextMode = TextBoxMode.MultiLine; //to add spaces LiteralControl space = new LiteralControl();
space.Text = " ";
LiteralControl space1 = new LiteralControl();
space1.Text = " ";
LiteralControl space2 = new LiteralControl();
space2.Text = " ";
//creating button Button btnok = new Button(); btnok.ID = "btnsub"; btnok.Width = 60; btnok.Text = "Submit"; btnok.Visible = true; btnok.CausesValidation = false; btnok.CommandName = "Submitinfo"; //adding controls to panel
panel1.Controls.Add(lblcname); panel1.Controls.Add(txtcname); panel1.Controls.Add(new WebControl(HtmlTextWriterTag.Br)); panel1.Controls.Add(lbltimeperiod); panel1.Controls.Add(ddl1); panel1.Controls.Add(space); panel1.Controls.Add(space); panel1.Controls.Add(txtyear); panel1.Controls.Add(space1); panel1.Controls.Add(ddl2); panel1.Controls.Add(space2); panel1.Controls.Add(txtyear1); panel1.Controls.Add(new WebControl(HtmlTextWriterTag.Br)); panel1.Controls.Add(lblpos); panel1.Controls.Add(txtpos); panel1.Controls.Add(new WebControl(HtmlTextWriterTag.Br)); panel1.Controls.Add(lbldiscription); panel1.Controls.Add(txtdisc); panel1.Controls.Add(btnok); panel1.Controls.Add(btncomp); //form1.Controls.Add(panel1); ContentPlaceHolder cph = this.Form.FindControl("ContentPlaceHolder2") as ContentPlaceHolder; cph.Controls.Add(panel1); btnok.Click +=new EventHandler(btnok_Click); }
when i am calling this method at pageload event it works fine
but when calling at linkbutton's click event the submit button does not work
so
i want to add that submit button to Ajax Update panel at code behind
but don't know how?
plz sombody help me.......
Hi pallavi,
In order to persist the events for dynamically created controls, you will have to register them on Page load or Page Init. The best would be to do this on Page Init so that you will keep Page load clean for other purpose. Otherwise, the way you are trying the event will be lost. Why? It's because once you click LinkButton, the code first passes in the link button and the goes again tru the page lifecycle, including page_init and page_load to create the events and other stuff for the page to load correctly.
I hope this clears up your doubts.
Regards,Hajan
Posted: 6/8/2011
Thanks Hajan a lot it's solve my problem
pallavi karpe said: Thanks Hajan a lot it's solve my problem
I'm glad. You are always welcome.