简体   繁体   English

c#.net更改标签文本

[英]c# .net change label text

Hello for I trying to use this code but for some reason it doesn't work. 您好我试图使用此代码但由于某种原因它不起作用。 Really need help with this. 真的需要帮助。 The problem is that the label doesn't change name from "label" when I enter the site. 问题是当我进入网站时,标签不会从“标签”更改名称。

<asp:Label ID="Label1" runat="server" Text="label"></asp:Label>


<% 
    Label1.Text = "test";
    if (Request.QueryString["ID"] != null)
    {

        string test = Request.QueryString["ID"];
        Label1.Text = "Du har nu lånat filmen:" + test;
    }

     %>

you should convert test type >>>> test.tostring(); 你应该转换测试类型>>>> test.tostring();

change the last line to this : 将最后一行更改为:

Label1.Text = "Du har nu lånat filmen:" + test.tostring();

Old question, but I had this issue as well, so after assigning the Text property, calling Refresh() will update the text. 老问题,但我也有这个问题,因此在分配Text属性后,调用Refresh()将更新文本。

Label1.Text = "Du har nu lånat filmen:" + test;
Refresh();

Have you tried running the code in the Page_Load() method? 您是否尝试在Page_Load()方法中运行代码?

protected void Page_Load(object sender, EventArgs e) 
{

         Label1.Text = "test";
        if (Request.QueryString["ID"] != null)
        {

            string test = Request.QueryString["ID"];
            Label1.Text = "Du har nu lånat filmen:" + test;
        }
}

If I understand correctly you may be experiencing the problem because in order to be able to set the labels "text" property you actually have to use the "content" property. 如果我理解正确您可能遇到问题,因为为了能够设置标签“text”属性,您实际上必须使用“content”属性。

so instead of: 而不是:

  Label output = null;
        output = Label1;
        output.Text = "hello";

try: 尝试:

Label output = null;
            output = Label1;
            output.Content = "hello";

When I had this problem I could see only a part of my text and this is the solution for that: 当我遇到这个问题时,我只能看到我文本的一部分,这就是解决方案:

Be sure to set the AutoSize property to true. 务必将AutoSize属性设置为true。

output.AutoSize = true;

  Label label1 = new System.Windows.Forms.Label
//label1.Text = "test";
    if (Request.QueryString["ID"] != null)
    {

        string test = Request.QueryString["ID"];
        label1.Text = "Du har nu lånat filmen:" + test;
    }

   else
    {

        string test = Request.QueryString["ID"];
        label1.Text = "test";
    }

This should make it 这应该成功

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

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