UserControl

  • Thread starter Thread starter Hai Nguyen
  • Start date Start date
H

Hai Nguyen

Hi all

I created a user control called temp1.ascx which contains several textboxes
and a button. I also have a webform name Web1.aspx.

In the web form Web1.ascx, I have this code
if(!this.IsPostBack)
{
PlaceHolder1.Controls.Add(this.LoadControl("temp1.ascx"));
}
else
{

}
In the web form temp1.ascx, I have this code
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
}
else
{
}
}

private void Button2_Click(object sender, System.EventArgs e)
{
Session[0] = txtKeyWord.Text;
Session[0] = txtURL.Text;
}

Here are my questions:
1/ Why does my usercontrol disappear after I hit the submit button? Do I
have to Load the control during the postback?
2/ How should I pesist my value entered on both the webform and usercontrol

Please provide me any examples with UserControls, article

Thanks
 
Hi,

1) any control that added dynamically to page should be added every time
page is called (even in postback). This rule includes user controls as
well.

2) any control that will emit as INPUT tag will persist data by
submitting it data as part of Form that send to server. Other controls
might persist there values using ViewState.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top