簡體   English   中英

在 web 表單中單擊按鈕時顯示文本框的值

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

我想在單擊按鈕時根據用戶選擇在文本框中出現一個字符串,我不知道該怎么做,這是代碼:

    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)
    {

    }

嘗試這個:

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

1.使用 label 並從 label1 編輯文本到您想要顯示價格的貨幣? 1:美元或 2:歐元。

2.使用另一個label,您要在其中顯示貨幣並將其命名為lbl_currency。

3.使用文本框並將其命名為 txt_choice。

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");
    }

}

您需要有一個名為 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