【发布时间】:2013-10-01 00:01:25
【问题描述】:
我的用户控制有问题。我无法从用户控件调用方法。 我的 default.aspx 包含更新面板。因为我不想重新发回页面。
我的default.aspx页面是:
public partial class Page_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Load();
}
private void Load()
{
if (Session["User"] == null)
{
ApplicationController.Controls.Add(new UserControl().LoadControl("View/Public/Login.ascx"));
}
else
{
ApplicationController.Controls.Add(new UserControl().LoadControl("View/Public/Welcome.ascx"));
}
}
}
和动态添加的用户控件是:
public partial class View_Public_Login : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAssetsGiris_Click(object sender, EventArgs e)
{
var user = new Kys.Dbo.Assets.user()
{
UserId = txtEmail.Text.Trim(),
Pwd = txtPwd.Text.Trim()
}.Login();
if (user != null)
{
Session["User"] = user;
}
}
}
如何从用户控件调用Load()方法?
【问题讨论】:
-
创建一个事件处理器,让你的
default.aspx页面注册到它。 -
感谢您的回复。你可以给我发个例子吗?
-
谢谢,但我没有通过拖动控件添加。我已经在占位符上动态添加了。