Solved

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

Posted on 2014-01-08
2
304 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

695 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