Hi,

In my asp.net page, I have the following line inside an UpdatePanel:

<input type="text" id="userInput" onblur="DisplayWord()" onkeyup="SearchWord(event, this.value)" />

Is there a way to retrieve the input value in the code behind (VB.NET)?

Thanks,

Ana

Dani AI

Generated

Two practical approaches work for the scenario in this thread (inside an UpdatePanel): read the posted form value on a postback, or convert the input into a server control so the value is available directly in code-behind. As pointed out, reading HTTP form data is the simplest when you do not want runat="server". As hinted, server-side event handling only applies once the control participates in postbacks.

Checklist and VB.NET examples:

  • Make sure the input has a name attribute (browsers submit values by name, not id), and that it sits inside the page form.
  • Request.Form is populated only after a postback (async or full). If using UpdatePanel, ensure a control triggers the async postback or add an appropriate trigger.
' in Page_Load or an async-postback handler
Dim userValue As String = Request.Form("userInput")
If Not String.IsNullOrEmpty(userValue) Then
    ' process userValue
End If

If you convert the element to a server control you can read its property directly:

' with an asp:TextBox ID="txtUser" runat="server"
Dim val As String = txtUser.Text

Troubleshooting notes: missing name or placing the input outside the form prevents submission; JavaScript-only handlers do not reach server unless they cause a postback or call a WebMethod/PageMethod. See the Microsoft docs for the Request.Form collection for full behavior and examples: HttpRequest.Form.

Recommended Answers

All 3 Replies

Handles the Enter, Leave, and KeyPress events.

Handles the Enter, Leave, and KeyPress events.

What the heck? this has nothing to do with what Ana asked...

I am also interested in learning how to get the input value from the code behind without making the INPUT control have the "RUNAT server" code.

Thanks

I think I got it, use this to get the value of the input from the code behind:

String.Format("{0}", Request.Form["MyInputBox"])

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.