ASP.NET中的textBoxChanged事件 [英] textBoxChanged event in ASP.NET

查看:81
本文介绍了ASP.NET中的textBoxChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如;

当我在TextBox1控件上写东西时,我想将textBox1的计数分配给textbox2.该代码可在WindowsForm中使用.

请告诉我..

For example ;

When i write something on TextBox1 control , I want to assignt the count of textBox1 to textbox2..But it doesnt work..How can i overwhelm this problem in ASP.NET ? The code works in WindowsForm.

Please infor me ..

thanks for in advance.

推荐答案

这是怎么回事:
What about this:
textBox2.Text = textBox1.Text.Length.ToString();


此事件被触发,该文本框的内容在发布到服务器 [
This event is fired the content of the text box changes between posts to the server[^].

Thus you do not see the results you would expect to see on Windows Forms.

You can use Javascript to handle the textchange event of the text box and allow the second text box to refresh.

E.g.
<script type="text/javascript">
    function TextChange(tBox) {
            text2 = tbox;
    }
</script>


当然,它不起作用.

您不能更改文本框的值,除非您进行物理键入,然后将表单发布回服务器,然后让服务器通过代码更改该值,或者使用Javascript在客户端更改该值.

您没有提及更改值的方法,只是大声呼救.

因此,在没有看到您的代码的情况下,我对如何帮助您一无所知.

[改进]

根据您的措辞,我假设您在谈论服务器端处理

因此,您可以在文本框中添加
Well of course it doesn''t work.

You can''t change the value of a textbox unless you physically type it in, post the form back to the server, and let the server change the value via code, or use Javascript to change the value on the client side.

You made no mention of your method to change the value, just a shout out for help.

So without seeing your code, I have no clue in how to help you out.

[IMPROVEMENT]

Based on your wording, I''m going to assume that your talking about server side processing

So on your textbox, you can add
<asp:TextBox id="Textbox1" OnTextChanged="EventHandler" />



并为事件处理程序创建一些代码



And create some code for the event handler

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   Textbox2.Text = Server.HtmlEncode(TextBox1.Text);
}



归功于Microsoft的信用



credit to microsoft


这篇关于ASP.NET中的textBoxChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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