Monday, October 26, 2009

Calling method from one user control from other usercontrol with out using property.

Take this scenorio, i have button and event in the first user control.

and i have label in the other usercontrol.

when i click on the button have to assign some value for label of other usercontrol with

out using the property


Step 1:

create first user control with following control and method.

<asp:Button ID="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Submit" />

public void btnSubmit_Click(object sender, EventArgs e)
{
test2 t2 = (test2)Page.FindControl("test2");

t2.callBTN(sender, e);

}
step 2:


create second user control with label with assigning value.

<asp:Label ID="lbltest" runat="server"></asp:Label>


public void callBTN(object sender, EventArgs e)
{
lbltest.Text = "DDDD";
}