在asp.net中单击事件链接按钮不触发 [英] Link Button in asp.net click event not firing

查看:146
本文介绍了在asp.net中单击事件链接按钮不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:LinkButton ID="lbDownloadFile" name = "lbDownloadFile" runat="server" CausesValidation="false" 
                            onclick="lbDownloadFile_Click" />

我有这样的链接按钮。在点击:

I have this link button. on click:

protected void lbDownloadFile_Click(object sender, EventArgs e)
{    //here is my debug pointer/breakpoint
    .........................
}

但这一事件不会开火。我的Page_Load()事件被触发。如何解决这个问题呢?

but this event is not firing. my Page_Load() event is firing. How to solve this problem?

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        if (Session[Antrage_AnfrageSessionNames.AgntNr] == null)
        {
            Response.Redirect("../UserSessionError.aspx");
        }

        try
        {
            if (Request.QueryString["Kundennummer"].ToString() != null)
            {
                //If kundennummer exists in QueryString then stores it to further use 
                kundennummer = Request.QueryString["Kundennummer"].ToString();                    
            }
        }
        catch
        {
            kundennummer = string.Empty;
        }
    }
}

编辑:

我加入code,有什么火狐萤火显示我各自对LinkBut​​ton的。

I am adding the code, what FireFox firebug shows me respective to the LinkButton.

我觉得产生的自发的 HREF 这里的主要问题。

I think the auto generated href is the main problem here.

推荐答案

@belogix评论是好

@belogix comment is Good

这是正常的ASP .NET的WebForms页面生命周期...页面加载的部分被称为EVERY时间回发发生。 pageLoad的后您的活动应该那么火......但你在做页面加载任何可能阻止这种情况发生?

This is part of the normal ASP .NET WebForms Page Lifecycle... Page Load is called EVERY time a postback occurs. After PageLoad your event should then fire... BUT Are you doing anything in Page Load that would stop this from happening?

我觉得你的页面加载方法都没有做错任何事。可能是你的链接按钮从页面加载事件重装。

样本误差

如果您在使用网格视图,也该链接按钮,在网格内,你都在做这样的事情。

If you using grid view and also this link button in inside of your grid, You are doing this things


  • 写网绑定方法

  • Write Grid bind method

然后你叫页面加载事件电网绑定方法

then you called the grid bind method in page load event

您code样子现在

Page_load()
{
// called here Grid bind method
} 

现在,每一个网格重装后回来。

Now, the grid reload on every post back .

解决方案

现在,你必须要设置!的IsPostBack ,然后调用网格绑定方法中的里面!的IsPostBack

Now you must need to set !IsPostBack and then call the grid bind method in inside of !IsPostBack

在code样子

Page_load()
{
if(!IsPostBack)
{
// called here Grid bind method

}
} 

这是你的问题。 ,也这是我的猜测。

请告诉我,如果你不使用任何控件(GridView的,列表视图等)

Please tell me if you not use any controls(Gridview,listview,etc)

修改

您code工作给我,如果我不写在页面加载事件的任何code

Your code is working to me if i don't write any code on page-load event

请参阅

Default.aspx的

 <asp:LinkButton ID="lbDownloadFile" Text="he he he" name="lbDownloadFile" runat="server" CausesValidation="false" OnClientClick="lbDownloadFile_Click"
        OnClick="lbDownloadFile_Click" />

和服务器端的code是

and server side code is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      // Empty code 
    }

    protected void lbDownloadFile_Click(object sender, EventArgs e)
    {
    }
}

这是为我好,所以你错过了页面加载事件什么

this is fine for me, So you missed anything in page load event

* 的OnClientClick 的onclick 没有任何问题。在页面加载事件所造成的问题,

*OnClientClick and onclick have not any problems. The problems created on pageload event,

请发表您的页面加载 code,否则我们解决不了。 :)

Please post your pageload code, otherwise we can't solve it. :)


  • 请检查链接按钮,在外面你的表单元素。该链接按钮的形式应为元素中

和你的页面加载事件应

保护无效的Page_Load(**对象发件人,EventArgs的**)
        {
     // code
        }

protected void Page_Load(){}

您已经错过

object sender, EventArgs e

这篇关于在asp.net中单击事件链接按钮不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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