tags:

views:

49

answers:

5

I have this in my ASPX page:

<input id="MY_LAST_FOCUS" name="MY_LAST_FOCUS" type="text" runat="server" />

In the Form Load of my VB.NET code behind I have this:

Dim s as String = Request("MY_LAST_FOCUS")

Why is s always empty even though the MY_LAST_FOCUS HTML text box has text in it?

+5  A: 

Why don't you use:

<asp:Textbox ID="MY_LAST_FOCUS" runat="server">

then in your code_behind you can access:

Dim s as String = MY_LAST_FOCUS.Text
Jack Marchetti
@Jhonny thanks for correcting my semi-colon. Took me months to remember to put it in when I switched to C#
Jack Marchetti
I think you mean MY_LAST_FOCUS.Value, as this is an HTML control. I don't thinki setting the runat server property to TRUE should have been necessary. Shouldn't I have been able to get the value from the Request collection w/o setting the RunAt property? Why didn't it work the way I did it? Note that "Request" and "Request.Form" are functionally equivalent and neither worked.
Velika
@Jack It happens to me all the time !!
Jhonny D. Cano -Leftware-
+2  A: 
Dim s as String = Request.Form(MY_LAST_FOCUS)

This works for me.

I agree with @Jack Marchetti though.

Dustin Laine
No, Request and Request.Form are identical and "[" is C# syntax.
Velika
Fixed, see updated response as I changed it.
Dustin Laine
@Velika: actually, they are not identical. If you just use Request, it will check the query string first, then the form, then cookies, and finally server variables. Request.Form goes right to the form and skips all the other junk.
Ray
A: 

If you want to access directly from the request, then use the UniqueID of the control:

Request.Form[MY_LAST_FOCUS.UniqueID]
Ray
A: 

I agree with Jack, but if you want to keep it a plain old HTML input box, you could just get the value of it:

Dim s As String = MY_LAST_FOCUS.Value

This only works as long as you keep runat="server" on it though. And like Jack points out, you probably should just use an ASP.NET TextBox control instead.

Aaron Daniels
The lightest weight approach is a simple HTML text box that does not have RunAt Server set. Shouldn't I be able to get the value in that HTML textbox using the Request FORMS collection? I'm thinking that this is the typical way in Classic ASP and that it should still be available in ASP.NET
Velika
A: 

Its empty because you seem to be grabbing from the Request object for something named what your input is, and not grabbing the contents of your input itself.

Jason M