7

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;
    }

     %>
3
  • You should be getting an error for an unquoted string, it needs to be Text='label', is this just a copy error in the question post? Commented May 26, 2010 at 20:51
  • 1
    Did you try putting a break point in your if statement and run the debugger to check that your code setting the Text property is actually reached? Also there is a typo in your <asp:Label> tag for the Text attribute where you are missing some quotes so if you copied your code directly from your apsx page then I am surprised that it actually compiles and runs :-) Commented May 26, 2010 at 20:54
  • 1
    Are you sure QueryString["ID"] in not null? Commented May 26, 2010 at 21:44

6 Answers 6

9

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

change the last line to this :

Label1.Text = "Du har nu lånat filmen:" + test.tostring();
Sign up to request clarification or add additional context in comments.

Comments

4

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();

Comments

3

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;
        }
}

Comments

1

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";

Comments

1
  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

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.