2

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 Answers 5

5

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
Sign up to request clarification or add additional context in comments.

3 Comments

@Jhonny thanks for correcting my semi-colon. Took me months to remember to put it in when I switched to C#
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.
It happens to me all the time !!
2
Dim s as String = Request.Form(MY_LAST_FOCUS)

This works for me.

I agree with @Jack Marchetti though.

2 Comments

No, Request and Request.Form are identical and "[" is C# syntax.
@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.
1

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

Request.Form[MY_LAST_FOCUS.UniqueID]

Comments

0

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.

1 Comment

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
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.