简体   繁体   English

在 web 表单中单击按钮时显示文本框的值

[英]display a value of the text box when the button is clicked in a web form

I want when the button is clicked a string comes on the textbox based on user selection, I don't know how to do that this is the code:我想在单击按钮时根据用户选择在文本框中出现一个字符串,我不知道该怎么做,这是代码:

    protected void Button1_Click(object sender, EventArgs e)
    {

        //DECLARE A STRING VARIABLE 
        String choice = "";
        //LET THE USER SELECT BETWEEN TWO VALUES TO DISPLAY PRICE OF THE BOOK
       Response.Write("<script>choice=window.prompt('Which Currency you want the price display ? 1 : Dollar or 2: Euro');" + "if(choice=='1'){ document.writeln('$22.43');}" + "if(choice=='2') document.write(' 20.55 EUR');" + "</script>");


    }

    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

Try this:尝试这个:

string yourString = "heyheyhey";字符串 yourString = "嘿嘿嘿"; TextBoxName.Text = yourString; TextBoxName.Text = yourString;

1.Use label and edit text from label1 to Which Currency you want the price display? 1.使用 label 并从 label1 编辑文本到您想要显示价格的货币? 1: Dollar or 2: Euro. 1:美元或 2:欧元。

2.Use another label in which you want display the currency and name it as lbl_currency. 2.使用另一个label,您要在其中显示货币并将其命名为lbl_currency。

3.Use a text box and name it as txt_choice. 3.使用文本框并将其命名为 txt_choice。

4.use button name it as btn,double click button and in the click event enter this code. 4.使用按钮命名为btn,双击按钮并在点击事件中输入此代码。

protected void btn_Click(object sender, EventArgs e)
{

    if(Convert.ToInt32(txt_choice.Text)==1){
     lbl_currency.Text="$22.43";
    }
    else if(Convert.ToInt32(txt_choice.Text)==2){
     lbl_currency.Text="20.55 EUR";
    }
    else{
     MessageBox.Show("Wrong Input");
    }

}

You need to have control called RadioButtonList for selecting your currency then in code behide您需要有一个名为 RadioButtonList 的控件来选择您的货币,然后在代码中隐藏

protected void btn_Click(object sender, EventArgs e)
{

    if(yourID_RadioButtonList.SelectedValue)=="Something"){
     lbl_currency.Text="Your_Value1";
    }
    else {
     lbl_currency.Text="Your_Value2";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM