Friday 12 October, 2007

Refresh A User Control within a ASP.NET page

Create a public method (example : public void refresh()) where you'll Bind the usercontrol's controls with Datas...
When you need to refresh the user Control call this method ! (in a event for example)

in user control :
public void refresh()
{
DropDownListUsers.DataSource=yourdatesource;
DropDownListUsers.DataBind();
}

And in your Page_Load (in UserControl) you'll have :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
refresh();
}
}


In the page where you use your UserControl :
protected void ButtonValid_Click(object sender, EventArgs e)
{
YourUserControl1.refresh();
}

Hits4Pay