C # .net change label text

Hello, I am trying to use this code, but for some reason it does not work. Actually need help with this. The problem is that the label does not change the name from the "label" when entering 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;
    }

     %>
+3
source share
6 answers

you should convert the type of test → → test.tostring ();

change the last line as follows:

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

Have you tried to run the code in the Page_Load () method?

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;
        }
}
+2
source

, , , "text" , "content".

:

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

:

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

An old question, but I also had this problem, so after assigning the Text property, the call Refresh()will update the text.

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

When I had this problem, I could only see part of my text, and this is the solution for this:

Be sure to set the AutoSize property to true.

output.AutoSize = true;

0
source
  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";
    }

It should do it

0
source

Source: https://habr.com/ru/post/1747257/


All Articles