在回发后动态添加的按钮处理事件 [英] Handling an event on a dynamically-added Button after postback

查看:141
本文介绍了在回发后动态添加的按钮处理事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有,我有一个链接按钮更新面板,当用户点击链接按钮全部内容被清零,文本框显示在该用户输入的东西,当用户按下回车键键,更新面板应被刷新或者被更新或所有内容重新填充。

Basically, I have an update panel in which i have a link button, when user clicks on the link button all the contents are cleared and textbox shows up in which user enters something and when user hit enter key, the update panel should be refreshed or gets updated or repopulated with all the contents .

我该怎么办呢?

我试图做到这一点的方法是,当链接按钮的事件处理程序被激发,我创建了一个隐藏式按键动态,并为其分配一个新的事件处理程序,当用户点击进入key.This新的动态按钮将被解雇链接按钮事件处理中产生。在这个新的按钮事件处理,我会重新填充内容了。

The way I am trying to do this is that when event handler of link button is fired, I created a hidden button dynamically and assign it a new event handler which will get fired when user hits enter key.This new dynamic button is created inside link button event handler. In this new button event handler I will repopulate the contents back.

我的方法的问题是动态创建按钮的事件处理函数不是被解雇。
为什么???

The problem with my way is the event handler of dynamically created button is not fired. Why ???

请尝试在C#来回答。
先谢谢了。

Please try to answer in c#. Thanks in advance.

问候,

我的code#

    protected void Submit_Click1(object sender, EventArgs e)
    {
        Label1.Text = TextBox1.Text + TextBox2.Text + " are sucessfully registered";
        Button mento = new Button();
        mento.cssclass = "invisible";
        mento.Click += new EventHandler(mento_click);
        // here this new mento button is attached to update panel
        updatepanel1.ContentTemplateContainer.Controls.add(mento);
    }

现在的问题是mento_click事件处理程序不被解雇???

Now the problem is mento_click event handler does not get fired ???

推荐答案

您可以赶上回车键,在文本框中?

You can catch the enter key, in the textbox?

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //add event keydown
        textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);

    }
    void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        switch (e.KeyCode )
        {

            case Keys.Enter:
                //YOur updatecode here:
                MessageBox.Show("You press enter");
                break;

            default:
                break;
        }
    }
}

这篇关于在回发后动态添加的按钮处理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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