【问题标题】:How to call method from Dynamically Added UserControls with Delegate如何使用委托从动态添加的用户控件调用方法
【发布时间】: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页面注册到它。
  • 感谢您的回复。你可以给我发个例子吗?
  • 谢谢,但我没有通过拖动控件添加。我已经在占位符上动态添加了。

标签: asp.net delegates


【解决方案1】:
var usercontrol = (View_Public_Login ).LoadControl("View/Public/Login.ascx");
usercontrol.Load()....
ApplicationController.Controls.Add(usercontrol);

【讨论】:

  • 请解释您的答案,以使其更好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-23
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 2010-12-14
相关资源
最近更新 更多