在文本框中输入的值应动态显示 [英] Values entered in the textbox should be displayed dynamically

查看:84
本文介绍了在文本框中输入的值应动态显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASPX页面中有一个文本框和一个按钮控件.应当动态显示在文本框中输入的值.

I have one textbox and one button control in my ASPX page. Values entered in the textbox should be displayed dynamically.

推荐答案

好.那么,出什么问题了?

服务器端事件中的按钮单击事件:
myTextbox.Text = "my dynamic text";

更新:
基于等待,您是否要求有人在文本框中输入文本,然后单击按钮,然后该值显示在网页上,如果再次执行该操作,则将显示新值和以前的值?

这意味着您也要保留较早的文本.好的.

MyPage.aspx.cs的代码隐藏:
Ok. So, whats the problem?

In button click event on server side event:
myTextbox.Text = "my dynamic text";

UPDATE:
Based on wait are you asking that some one enters text into the text box, then clicks the button then the value is displayed on the webpage and if they do it again the new value and the previous value(s) are displayed?

This means you want to preserve the earlier text too. Ok.

Codebehind MyPage.aspx.cs:
//define a page level variable OR a hidden field 
// lets name it allValuesOfTextbox
// Now, in button click event:
allValuesOfTextbox += myTextbox.Text ; // if it was a page level variable
someLabelOnWebpage = allValuesOfTextbox; 

allValuesOfTextbox.Value += myTextbox.Text ; // if hidden field
someLabelOnWebpage = allValuesOfTextbox.Value;


Sandeep是正确的,您只需要向变量添加文本,然后将变量分配给框即可:

Sandeep is right, you just need to add text to a variable, and then assign the variable to the box:

string fullText = "";
void AddText(string text)
{
    fullText += text;
    //or this one if you want to display multiline text
    //don''t forget to set the Multiline property of your text box to true in the designer.
    //fullText += Environment.NewLine + text;
    UpdateTextBox();
}
void UpdateTextBox()
{
    textbox.Text = fullText;
}


这篇关于在文本框中输入的值应动态显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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