Passing Value from .aspx page to user control using C#/ ASP.Net

Step1: Create property on User Control for setting and getting a value.

public Guid? ToRoleID
{
get
{
if (ViewState["idRole"] == null)
{
return Guid.Empty;
}
return Guid.Parse(ViewState["idRole"].ToString());
}
set { ViewState["idRole"] = value;}
}

Step2: Assign value to user control property in .aspx page

UCRoleMenuPermissions1.ToRoleID = idRole;

Step3: Override DataBind method for user control in .aspx page

public override void DataBind()
{
string To = ToRoleID.ToString();
FillGrid();
}

Step4: Call User Control Data Bind method in .aspx page

UCMyControl.DataBind();

Leave a Reply

Your email address will not be published. Required fields are marked *