我想永久更改labelcontrol的文本 [英] i want to change in text of labelcontrol permanently

查看:55
本文介绍了我想永久更改labelcontrol的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

defaut.aspx页面编码

defaut.aspx page coding

</head>
<body>
    <form id="form1" runat="server">
    <div>
        welcome: &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Label"></asp:Label><br />
        You visted on: &nbsp;
        <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Label"></asp:Label></div>
        <br />

        <hr width="40%" align="left" />
        <br />
        <br />

        Enter your name: &nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;
        <asp:Button ID="Button1" runat="server" Text="Save"  />
    </form>
</body>
</html>



defaut.aspx.cs编码



defaut.aspx.cs coding

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

       

            string hh;
            hh = Request.QueryString["name"].ToString();
            Profile.Name = hh;
            Profile.Save();
            Label1.Text = hh;
       
    protected void Page_UnLoad(object sender, EventArgs e)
    {
        Profile.VisitedOn = DateTime.Now;
        Profile.Save();
    }


gg.aspx 

 page coding from which i will send a name to default page through
query string

<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    
    </div>
    </form>
</body>
</html>
    

gg.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?name=" + TextBox1.Text);
    }
}



now question is that values changed of label in default.aspx page when i go from gg.aspx page to defaut.aspx page but when i open directly default.aspx page 
values of label text retained.
i want that when i enter through default.aspx page values shoud be changed.
plzz anybody

推荐答案

<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Label">



看到上面以粗体显示的Text="Label"部分吗?指定直接加载页面时想要在此处看到的任何文本,应该是该文本.

如果文本是动态的(来自数据库或基于某种逻辑),请在页面的Page_Load事件中对其进行更改.



See the Text="Label" part in bold above? Specify whatever text you want to see here when the page is loaded directly and that should be it.

If the text is dynamic (either coming from database or based on some logic), change it in your Page_Load event of the page.


这篇关于我想永久更改labelcontrol的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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