Thursday, March 22, 2012

Want button event to happen everytime...

Can some explain to me why, this doesn't write hello everytime I hit the button?
Also, can you tell me how to fix it?

*****************************************************************************
<%@dotnet.itags.org. Page Language="VB"%>
<script language="VB" runat="server">
Dim TestString As String
Sub Page_Load(Source As Object,e As EventArgs)
Test1()
End Sub

Function Test1()
TestString = "Hello Jackie"
Response.Write(TestString & "<br>")
End Function

Sub Button_Click(Source As Object,e As EventArgs)
Test2()
End Sub

Function Test2()
Response.Write(TestString)
End Function

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form runat="server">
<table width="347" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="347" height="132" valign="top"><asp:label ID="test" runat="server"></asp:label>
<asp:button ID="TestButton" Text="Update" OnClick="Button_Click" runat="server" /></td>
</tr>
<tr>
<td height="38"> </td>
</tr>
</table>
</form>
</body>
</html>Hello, first time the page load, it prints the string, but next time you click the button and u cause a postback to the specified method, nothing is being written, because the string has lost its value, since u are only calling the method button_click and not the whole page !!!!!!!

try the first time you write the message to store the message in a session variable, this way everytime u want to print anything, u can get it from the session variable.

hope this helps
Thanks!!

0 comments:

Post a Comment