ASP.net的LinkBut​​ton在$ C $ onclick事件cbehind不工作 [英] ASP.net Linkbutton with onclick event in codebehind not working

查看:76
本文介绍了ASP.net的LinkBut​​ton在$ C $ onclick事件cbehind不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导航的ASP LinkBut​​ton的下拉列表。这将用于注销,所以我有一个事件链接到code后面,在那里我将关闭并清空会话。但是,当我启动我的项目,它给这个错误:


  

CS1061:'ASP.main_aspx'不包含'LinkBut​​ton_Click',没有扩展方法'LinkBut​​ton_Click接受型ASP.main_aspx'的第一个参数的定义可以找到(是否缺少using指令或程序集引用?)


这是我的aspx code

 <李>< ASP:LinkBut​​ton的ID =myLink的文本=注销的OnClick =LinkBut​​ton_Click=服务器/>< /李>

这背后是code

在code

 无效LinkBut​​ton_Click(对象发件人,EventArgs的发送)
    {
        Session.Clear();
        Session.RemoveAll();
        Session.Abandon();
        的Response.Redirect(的Login.aspx);
    }


解决方案

问题:您应该指定为保护访问修饰符 LinkBut​​ton的 点击事件,否则默认的访问修饰符私人将应用和的LinkBut​​ton 点击事件函数不能被访问。这就是为什么T =你所得到以下异常


  

ASP.main_aspx'不包含'LinkBut​​ton_Click'的定义......


解决方案:添加保护访问修饰符您<$ C $在隐藏文件code C>的LinkBut​​ton 点击事件

试试这个:

 保护无效LinkBut​​ton_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 for LinkButton Click Event otherwise by default access modifier private will be applied and LinkButton 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 as access-modifier for your LinkButton Click event in the code behind file

Try This :

protected void LinkButton_Click(Object sender, EventArgs e) 
{
   Session.Clear();
   Session.RemoveAll();
   Session.Abandon();
   Response.Redirect("Login.aspx"); 
 }

这篇关于ASP.net的LinkBut​​ton在$ C $ onclick事件cbehind不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆