cant chang按钮文本permonently [英] cant chang button text permonently

查看:111
本文介绍了cant chang按钮文本permonently的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过文本框更改button1的名称。这是aspx代码。

i want to change the name of button1 through text box. here is the aspx code.

<form id="form1"  runat="server">
    <div>
    <p id="our mission">
        <asp:Button ID="Button1" runat="server" Text="Button" />
        
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
        
    </p>
        <p>
            <asp:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" Visible="False" />
        
    </p>
    </div>
    </form>





这里是背后的代码。



here is the code behind.

protected void LinkButton1_Click(object sender, EventArgs e)
  {
      TextBox1.Visible = true;
      Button2.Visible = true;
  }
  protected void Button2_Click(object sender, EventArgs e)
  {

          Button1.Text = TextBox1.Text;


          Button1.ID = TextBox1.Text;
          Button2.Visible = false;
          TextBox1.Visible = false;



它暂时更改按钮文本但不是永久性的。请告诉我如何永久更改它。

谢谢


it changes the button text for the time being but not permanently. kindly tell me how to change it permanently.
Thanks

推荐答案

您需要在某处保留数据。您可以在服务器上使用文本文件,在page_load上读取文件并将内容作为按钮的.Text。并根据需要将新上下文保存到文件中。 StreamWriter / StreamReader将使用 Server.MapPath() [ ^ ]方法。
You need to persist the data somewhere. You could use a text file on the server and on page_load you read the file and place the contents as the .Text of the button. And save new context to the file as needed. StreamWriter/StreamReader will do the job with the Server.MapPath()[^] method.


这篇关于cant chang按钮文本permonently的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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