Value of an HTML element

  • Thread starter Thread starter Halo
  • Start date Start date
H

Halo

I have a HTML text box (NOT a TextBox server control) in
a .aspx page and a button server control. Is it possible
with ASP.NET to get the value of the HTML text box when I
click the button? How can I get the value of an HTML
element from C# on the server?

Thanks!
 
you could add a runat="server" to the input box

<input type="textbox" runat="server" id="yourinput" />

instead of bing a WebControls.TextBox it'll be an
HtmlControls.HtmlInputText

alternatively, you can always use Request.Form()...

Karl
 
Set the HTML Textbox's Runat property to"Server". You will then be able to
access the value from C#


Ibrahim Malluf
 
It is possible to do this, but you need to do a few things. First, set the
HTML textboxes runat=server. Then, declare the textbox in your code.
Include the following (as an example in C#):

using System.Web.UI.HtmlControls;

Now, inside of your class, you'll need to put something similar to this:

HtmlInputText myTextBox; // Make sure the name myTextBox is also the
name attribute of the HTML control

so your HTML code would look something like this:

<INPUT type="text" name="myTextBox" runat="server></INPUT>
 
Back
Top