In the below code I have 2 user controls sample.ascx
and sample1.ascx
.I have a button in sample.ascx
when I click the button it should call the method in sample1.ascx
. Pls help me to do this.
Sample.ascx
<%@ Register TagPrefix="gmas" TagName="FieldCont" Src="~/Controls/Sample1.ascx" %>
<asp:Button id="Savebtn" runat="server" Text="Save" OnClick="Save_Click" />
CodeBehind:
protected void Save_Click(object sender, EventArgs e)
{
}
Sample1.ascx
public bool IsValid()
{
}
protected void Save_Click(object sender, EventArgs e)
{
Sample1 ctrlB = new Sample1();
ctrlB.IsValid();
}
Make sure your user control code behind is Sample1 as mentioned below :
public partial class Sample1 : System.Web.UI.UserControl
and you can call IsValid method in button click event as mentioned below :
var control = new Sample1();
var isvalid = control.IsValid();
Note:
using
directive 我认为它必须简单,你可以尝试使用代码。
(new sample1()).<functionTocall>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.