ASP.net的LinkButton在$ C $ onclick事件cbehind不工作 [英] ASP.net Linkbutton with onclick event in codebehind not working
问题描述
我有一个导航的ASP LinkButton的下拉列表。这将用于注销,所以我有一个事件链接到code后面,在那里我将关闭并清空会话。但是,当我启动我的项目,它给这个错误:
CS1061:'ASP.main_aspx'不包含'LinkButton_Click',没有扩展方法'LinkButton_Click接受型ASP.main_aspx'的第一个参数的定义可以找到(是否缺少using指令或程序集引用?)
块引用>这是我的aspx code
<李>< ASP:LinkButton的ID =myLink的文本=注销的OnClick =LinkButton_Click=服务器/>< /李>
这背后是code
在code无效LinkButton_Click(对象发件人,EventArgs的发送)
{
Session.Clear();
Session.RemoveAll();
Session.Abandon();
的Response.Redirect(的Login.aspx);
}
解决方案问题:您应该指定
为保护
访问修饰符LinkButton的
点击
事件,否则默认的访问修饰符私人
将应用和的LinkButton
点击事件函数不能被访问。这就是为什么T =你所得到以下异常
ASP.main_aspx'不包含'LinkButton_Click'的定义......
块引用>解决方案:添加
保护
为访问修饰符
您<$ C $在隐藏文件code C>的LinkButton点击
事件试试这个:
保护无效LinkButton_Click(对象发件人,EventArgs的发送)
{
Session.Clear();
Session.RemoveAll();
Session.Abandon();
的Response.Redirect(的Login.aspx);
}I have an asp linkbutton in a navigation drop down list. It will be used for logging out and so I have an event linked to the code behind, where I shall close and empty the session. But when I startup my project it gives this error:
CS1061: 'ASP.main_aspx' does not contain a definition for 'LinkButton_Click' and no extension method 'LinkButton_Click' accepting a first argument of type 'ASP.main_aspx' could be found (are you missing a using directive or an assembly reference?)
this is my aspx code
<li><asp:LinkButton id="myLink" Text="Logout" OnClick="LinkButton_Click" runat="server"/></li>
and this is the code behind code
void LinkButton_Click(Object sender, EventArgs e) { Session.Clear(); Session.RemoveAll(); Session.Abandon(); Response.Redirect("Login.aspx"); }
解决方案Problem : You should specify
protected
access modifier forLinkButton
Click
Event otherwise by default access modifierprivate
will be applied andLinkButton
Click event function can not be accessed. that is why t=you are getting the following Exception'ASP.main_aspx' does not contain a definition for 'LinkButton_Click'......
Solution : add
protected
asaccess-modifier
for yourLinkButton
Click
event in the code behind fileTry This :
protected void LinkButton_Click(Object sender, EventArgs e) { Session.Clear(); Session.RemoveAll(); Session.Abandon(); Response.Redirect("Login.aspx"); }
这篇关于ASP.net的LinkButton在$ C $ onclick事件cbehind不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!