-1

我想显示标签(使隐藏的可见)并在单击时更改按钮的文本,并且能够再次单击该按钮以显示其原始文本并隐藏标签。`

    public partial class TestClick : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) 
        {

            btnShowButtonText.Text = "Button";
            lblShowText.Visible = false;

        }
    }
    protected void btnShowButtonText_Click(object sender, EventArgs e)
    {
        if (!Session.IsNewSession)
        {
            btnShowButtonText.Text = "Hide gift voucher details";
            lblShowText.Visible = true;
        }
    }      
4

2 回答 2

0

您可以使用隐藏字段来确定按钮和文本的状态:

  public partial class TestClick : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack) 
    {

        btnShowButtonText.Text = "Button";
        lblShowText.Visible = false;
    }
   }

protected void btnShowButtonText_Click(object sender, EventArgs e)
{
    if(hiddenField.Value == "0")
    {
       btnShowButtonText.Text = "Hide gift voucher details";
       lblShowText.Visible = true;
       hiddenField.Value = "1";
    }
    else
    {
       btnShowButtonText.Text = "Button";
       lblShowText.Visible = false;
       hiddenField.Value = "0";
    }
}   
于 2012-10-14T14:18:12.030 回答
0

您可以使用一个计数变量。像这样:

static  int cnt=0;
    protected void btnShowButtonText_Click(object sender, EventArgs e)
        {
    cnt++;
            if (cnt%2!=0)
            {
                btnShowButtonText.Text = "Hide gift voucher details";
                lblShowText.Visible = true;
            }
    if (cnt%2==0) 
            {

                btnShowButtonText.Text = "Button";
                lblShowText.Visible = false;

            }
        }  

当您第一次点击时,按钮文字为“隐藏礼券详情”,
下次按钮文字为“按钮”

于 2012-10-14T14:10:12.227 回答