UserControl

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
 
N

Natty Gur

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top