Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Values into text boxes

Status
Not open for further replies.

kennyaidan

Programmer
Apr 9, 2003
54
IE
Hi, i'm a beginner asp.net programmer and i need help with an error i keep getting. I'm trying to input a session value into a text box.
The code i have takes in a value from a text box,
<input type=&quot;text&quot; id=&quot;name&quot; size=&quot;15&quot; runat=&quot;server&quot;>

I then assign it a value
Session(&quot;sessionStoryId&quot;)=name.value

i redirect to another page
response.redirect(&quot;edit1.aspx&quot;)

And then in edit1.aspx i am trying to populate a text box with the &quot;sessionStoryId&quot; value.
<input type=text id=storyid value=<%= session(&quot;sessionStoryId&quot;) %> runat=server>

Can anyone please help because i don't know where i am going wrong.
Any help greatly appreciated
aidan
 
i'd start by using asp:textboxes webcontrols instead of input type=text boxe htmlcontrols, .net likes them better :) ...change to:
Code:
'sample textbox would be:
<asp:Textbox id=name runat=&quot;server&quot;></asp:Textbox>

your codebehind stuff...
Code:
Session(&quot;sessionStoryId&quot;) = name.Text

to assign it to your story id box, you would just do:
Code:
storyid.Text = Session(&quot;sessionStoryId&quot;)

i've never had good luck doing the inline <%%> stuff with .net...

hth.
 
thanks gagz, i'm going to try that now just one quick question where do i place the &quot;storyid.Text = Session(&quot;sessionStoryId&quot;)&quot; piece of code, do i put it in the text box declaration, similar to the following
<input type=text id=storyid storyid.Text = Session(&quot;sessionStoryId&quot;) runat=server>

or do i put it with in the script tag at the the top of the file and then call it further down in the text box, for example

<head>
<script runat=server>

storyid.Text = Session(&quot;sessionStoryId&quot;)

</script>
</head>


<input type=text id=storyid value=&quot;storyid.Text&quot; runat=server>

thanks
aidan
 
ok here's the deal... on whatever your first page is, you have some html... the asp:textbox replaces the input boxes..

so you have:
Code:
<form name=Form1 runat=server>
<asp:Textbox id=name runat=server></asp:Textbox>
</form>

then when that page is submitted and you assign it to the session variable, you access the textbox objects text attribute, and assign it to the session (in code behind or script block)
Code:
Session(&quot;sessionStoryId&quot;) = name.Text

then in your redirected page, you can assign it to the new text box in the codebehind page or script block:
Code:
storyid.Text = session(&quot;sessoinstoryId&quot;)

is that what you wanted?

 
thats great gagz, solved the problem and thanks for all the help, sorry for the late reply server went down
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top