为什么我的点击事件没有到达? [英] Why is my click event not being reached?

查看:94
本文介绍了为什么我的点击事件没有到达?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在* .ascx.cs文件中动态(在C#中)在Sharepoint页面上创建一个按钮:



I'm creating a button on a Sharepoint page dynamically (in C#) in my *.ascx.cs file:

Button btnSave = null;

protected void Page_Load(object sender, EventArgs e)
{
    base.OnPreRender(e);

    this.Controls.Add(new LiteralControl("<br />"));
    btnSave = new Button();
    btnSave.ID = "btnSave";
    btnSave.Text = "Save the Data";
    btnSave.Click += new EventHandler(btnSave_Click);
    btnSave.Visible = false;
    this.Controls.Add(btnSave);
}

protected void btnSave_Click(object sender, EventArgs e)
{
    btnSave.Text = "You clicked me!";
    PostTravelData ptd = new PostTravelData();
}





我在*中的客户端jQuery中将其设置为可见。 ascx文件:





I set it visible at the righ time in the client-side jQuery in the *.ascx file:

$('#btnSave').show();





但是,单击按钮不会到达btnSave_Click()事件 - 从未到达断点,也不是按钮的文字已更改。为什么不呢?



However, clicking the button does not reach the btnSave_Click() event - the breakpoint there is never reached, nor is the button's text changed. Why not?

推荐答案

('#btnSave')。show();
('#btnSave').show();





但是,单击按钮不会到达btnSave_Click()事件 - 从未到达断点,也不是按钮的文字已更改。为什么不呢?



However, clicking the button does not reach the btnSave_Click() event - the breakpoint there is never reached, nor is the button's text changed. Why not?


让我们看看:

这是服务器端的方式

Lets see:
this is the way of the server side
<asp:button id="btnSave" runat="server" text="Click me" xmlns:asp="#unknown" />





关于服务器(或你n直接在html中执行)



On the server (or you can do it in html directly)

btnSave.OnClick += btnSave_Click;







如果你试图显示/隐藏服务器端控件,这是不正确的:




This is incorrect if you're trying to show/hide server-side control:


' #btnSave')。show();
('#btnSave').show();





这是由于服务器端命名约定,它将所有容器名称添加到id前面,如ctl_00_ctl_01_btnSave。它应该是:



This is due to server side naming convention that adds all containers names in front of the id like ctl_00_ctl_01_btnSave. It should be:


这篇关于为什么我的点击事件没有到达?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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