c# .net change label text

前端 未结 6 1815
眼角桃花
眼角桃花 2021-01-05 07:21

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

相关标签:
6条回答
  • 2021-01-05 07:41

    Have you tried running 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;
            }
    }
    
    0 讨论(0)
  • 2021-01-05 07:43
      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

    0 讨论(0)
  • 2021-01-05 07:46

    you should convert test type >>>> test.tostring();

    change the last line to this :

    Label1.Text = "Du har nu lånat filmen:" + test.tostring();
    
    0 讨论(0)
  • 2021-01-05 07:47

    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.

    output.AutoSize = true;

    0 讨论(0)
  • 2021-01-05 07:56

    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.

    so instead of:

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

    try:

    Label output = null;
                output = Label1;
                output.Content = "hello";
    
    0 讨论(0)
  • 2021-01-05 07:57

    Old question, but I had this issue as well, so after assigning the Text property, calling Refresh() will update the text.

    Label1.Text = "Du har nu lånat filmen:" + test;
    Refresh();
    
    0 讨论(0)
提交回复
热议问题