如何在更改动态创建的文本框文本时对函数进行Calll [英] How to Calll a function on change a dynaically created textbox's text

查看:64
本文介绍了如何在更改动态创建的文本框文本时对函数进行Calll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需点击一个按钮就可以创建一个文本框。

I have create a textbox by simply clicking a button.

TextBox txtGainMark = new TextBox();
txtGainMark.ID = count.ToString();
txtGainMark.Text = "GiveYourMark";
txtGainMark.Attributes.Add("onchange", "javascript:document.getElementById('lblDataOperation').innerHTML = this.value;");
placeholder.Controls.Add(txtGainMark);

当我更改txtGainMark的文本时,结果显示为标签lblDataOperation,但我希望将更改后的值转换为字符串变量,并将该值调用为C#函数参数。

when I change the txtGainMark's text, the result shown into a label "lblDataOperation", but I want to get the changed value into a string variable and call a C# function with that value as a parameter.

推荐答案

protected void Page_Load(object sender, EventArgs e)
   {
       TextBox textBox = new TextBox();
       textBox.TextChanged += new EventHandler(textBox_TextChanged);
   }

   protected void textBox_TextChanged(object sender, EventArgs e)
   {
       // Your code here
   }







希望这会有所帮助。




Hope this will help.


在将Textbox添加到占位符之前,只需将TextChanged事件绑定到它。



Before adding Textbox to placeholder, just bind TextChanged event to it.

{

    //... same previous code

    txtGainMark.TextChanged += new EventHandler(txtGainMark_TextChanged);
    placeholder.Controls.Add(txtGainMark);
}
protected void txtGainMark_TextChanged(object sender, EventArgs e)
{
    // Do your work here
}





如果有任何问题,请询问:)



Ask, if any problem :)


是的,请检查autopostback属性。您没有在文本chnage上提交该页面,这就是无法提交页面的原因。
Yes please check with autopostback property. You are not submitting the page on text chnage thats why unable to submit the page.


这篇关于如何在更改动态创建的文本框文本时对函数进行Calll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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