Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value from input html in codebehind c#

Tags:

html

c#

asp.net

I did some research and found out how I can read a value from the input html textbox.

This worked fine for me, but at once it doesn't work.

This is my code, it input html returns null

<input type="text" name="inpNickname" placeholder="Nickname" data-placement="right" data-toggle="tooltip" title="Nickname" id="txtNickname" runat="server"/>

<input type="text" name="inpPassword" placeholder="Password" data-placement="right" data-toggle="tooltip" title="Password" id="txtPassword" runat="server"/>

string Nickname = Request.Form["inpNickname"];
string Password = Request.Form["inpPassword"];

If I change the Request.Form[] to the ID's, it still doesn't work.

like image 333
Swag Avatar asked Jul 17 '13 15:07

Swag


People also ask

How to get HTML Input value in Code Behind in c#?

Solution 1. You can access the value of the control using Request object. Request["TextBoxID"] should give you the text in the textbox. Other option is - store the TextBox value in a Hidden Field onblur of the TextBox.


1 Answers

Since it is running at the server...

txtNickname.Value and txtPassword.Value will give you what you need.

When you specify runat="server" you are essentially giving a property to your codebehind class. So you can access that property and it's properties directly.

like image 187
bluetoft Avatar answered Sep 30 '22 02:09

bluetoft