c# - 在 Site.Master 页面中单击按钮会触发内容页面中的单击事件。

标签 c# asp.net master-pages mouseclick-event

我正在尝试在 Site.Master 页面中单击一个按钮以在内容页面中触发单击事件。

我知道母版页实际上在编译时变成了子类。

经过几个小时的谷歌搜索后,我尝试了几种不同的解决方案,但在网站上没有结果。

这是我应用的当前解决方案:

PageLoad()
{
Button btn = this.Master.FindControl("lbtnMaintenance") as Button;
            btn.Click += new System.EventHandler(MasterlbtnMaintenance);
  }


 private void MasterlbtnMaintenance(object sender, EventArgs e)
        {
            MaintenanceHomeScreen(true);
        }

最佳答案

//Created an Interface on .aspx page:
public interface ICommandable
{
    void LblMaintenanceClick(object argument, EventArgs e);
    } 

public partial class Default : Page, ICommandable
{
 public void LblMaintenanceClick(object sender, EventArgs e)
           {

             }
}

    // On master page: 
      public void lbtnMaintenance_OnClick(object sender, EventArgs e)
                 {
                        if (Page is ICommandable)
                    {
                         (Page as ICommandable).LblMaintenanceClick(sender, e);
                     }
                 else
                     throw new NotImplementedException("u NO WURK");

            }

关于c# - 在 Site.Master 页面中单击按钮会触发内容页面中的单击事件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26165561/

相关文章:

C# Complex Linq-如何获取 ID 或子 ID 匹配的对象

c# - C#中的触发事件

python - 像 Python 中的 MasterPage 概念

asp.net - 从 C# 代码增加 Http Runtime MaxRequestLength

.net-3.5 - 在母版页上填充菜单控件的最佳方法是什么?

asp.net - 母版页上的编译器错误

c# - 传入字典的模型项的类型为 'System.Threading.Tasks.Task` 1[System.Collections.Generic.IEnumerable`

c# - 使用restsharp put方法更新AtTask中的项目参数

asp.net - Silverlight 网站浏览器缩放问题

c# - 显示日历值