?
Solved

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

Posted on 2014-01-08
2
Medium Priority
?
305 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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