Solved

basic ASP.NET question:  changing a label in a function

Posted on 2014-01-08
2
303 Views
Last Modified: 2014-01-09
I am trying to change the text of label 1.  Here is my ASPX code:
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <%Test()%>
    </div>
    </form>
</body>

Open in new window


And here is my VB:
Protected Function Test() As Boolean
        Label1.Text = "hello world"
   response.write("hello")
        Return Nothing
    End Function

Open in new window


But the label does not change even though when I load the page, function "test" is executed (the response.write works)

I do not understand why the label doesn't change when function "test" is executed?  Can someone help?  How do I change the label within function "test"
0
Comment
Question by:arthurh88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 39767359
Your label doesn't change its text because it's loaded and rendered to the browser when you execute the Test function.

Try this instead:

<div>
    <%Test()%>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>

Open in new window

Now, the label's text is changed.

Hope that helps.
0
 
LVL 5

Expert Comment

by:Ronak Patel
ID: 39767444
Hi arthurh88,

You can also call Test() method on Page_Load event as shown in below code.

<body>
    <form id="form1" runat="server">
    <div>
		<asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>

Open in new window


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

	Test()

End Sub

Protected Function Test() As Boolean

	Label1.Text = "hello world"
	Response.Write("hello")
	Return Nothing

End Function

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 29
C# XML Get Values 4 37
Set the FileVersion of a website dll 1 29
Web page design problem 3 18
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question