3

我有一个Main.Master带有按钮的页面。
在设计视图中,我双击该按钮,它会在Main.Master页面中创建一个单击事件,如下所示;

<script runat="server">

    protected void btnKayit_Click(object sender, EventArgs e)
    {

    }
</script>

我希望它在Main.Master.cs页面上创建,当我这样做时,它会给我这个错误;

CS1061: 'ASP.main_master' does not contain a definition for 'btnKayit_Click' and no extension method 'btnKayit_Click' accepting a first argument of type 'ASP.main_master' could be found (are you missing a using directive or an assembly reference?)

我怎么解决这个问题?

编辑:aspx代码;

<asp:Button CssClass="arama" ID="btnKayit" runat="server" Text="Kayıt Ol" Height="30px"
                                    Width="75px" Style="margin: 0px; float: left; width: 75px; padding: 0px; margin-bottom: 0px;
                                    color: #d55355; font-size: 12px" onclick="btnKayit_Click" />
4

2 回答 2

0

验证 .master 和 .master.cs 文件中的命名空间。

检查主文件的指令...

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.Master.css"
Inherits="Main" EnableTheming="true" %>

这里,检查 CodeFile 属性的名称,它应该与 Master.cs 文件的类名相同

public partial class Main : System.Web.UI.MasterPage
于 2013-05-20T12:45:37.887 回答
0

根据您的错误消息,我认为您的母版页正在继承ASP.main_master类。您需要btnKayit_Click()ASP.main_master类中添加。基本上,您的代码应如下所示。

HTML:

//Please note the inherits attribute
<%@ Master Language="C#" Inherits="main_master" ... %>


<asp:Button CssClass="arama" ID="btnKayit" runat="server" ... 
            onclick="btnKayit_Click" />

后面的代码:

//Please note the class name here it should be same as inheriting class name
public partial class main_master : System.Web.UI.MasterPage
{
    //....

    protected void btnKayit_Click(Object sender, System.EventArgs e)
    {
    }
}
于 2013-05-20T13:05:03.610 回答