Thursday, March 29, 2012

Passing values from labels to text boxes via session variables

I'm passing label values from one page to text boxes in another page for user update. I'm using session variables, but I have been unable to display the passed values in the receiving text boxes. I'm not sure if the syntax is wrong or if the constructs are inappropriate. I'm new and need help.

<code>
SENDING PAGE:

<%@dotnet.itags.org. Page Language="vb" %>
<script runat="server"
Sub doSubmit(Source as Object, E as EventArgs)
Context.Items.Add("first", txtFirst.text)
Context.Items.Add("last", txtLast.text)
Server.Transfer("3.aspx")
End Sub

</script>
<html
<head>
<title>1.aspx</title>
</head
<body
<form id="form1" runat="server">
First Name: <asp:TextBox id="txtFirst" runat="server" /><br>
Last Name: <asp:TextBox id="txtLast" runat="server" />
<asp:Button id="button1" Text="Submit" onclick="doSubmit" runat="server" />
</Form>
</body>
</html
RECEIVING PAGE:

<%@dotnet.itags.org. Page Language="vb" %>
<script runat="server"
Sub Page_Load(Source as Object, E as EventArgs)

label1.text = "The Name you entered was : " & Context.Items("first") & " " & _
Context.Items("last")
textbox1.text = Context.Items("First")
textbox2.text = Context.Items("Last")

End Sub

</script>
<html>
<head>
<title>Second Page</title>
<asp:Label ID="label1" runat="server" />
</head>
<body>
<form name="Form1" runat="server">
<asp:TextBox id="textBox1" Text='<%# "textbox1" %>' runat="server"></asp:TextBox>
<asp:TextBox id="textBox2" Text='<%# "textbox2" %>' runat="server"></asp:TextBox>
</form>
</body>
</htmlIn the recieving pae's load event you're setting the value of the textbox so you don't need to bind the text box's value to itself (so just leave out the "Text=' etc." attribute).

Also, the items collection is case sensitive. You're adding items as "first" and "last" but you're trying to retrieve values from "First" and "Last". Choose a case and stick with it and the problem is resolved.
you made my day Chapel21. thanx for the prompt response and the explanation given, it makes a bit clearer what each line of code does.

sometimes I think I should've studied CGI scripting 5 years ago, when i had time to invest. by now, ASP .NET should've been simpler to understand and use, or may be not.. thanx again,

0 comments:

Post a Comment