Search

Wednesday, September 11, 2013
0 comments

How to access html form element in code file in ASP.NET

6:49 AMWednesday, September 11, 2013

The HtmlForm Class

The HtmlForm class can be used to access the HTML <form> element in the code file. If you add any HTML control to the form using ASP.NET IDE , the web form automatically converts that control into the object of the HtmlForm class. You can also create additional forms using the HtmlForm class, if required. All server controls that postback to the server must be placed between the opening and closing tags of an HTML form. You can use the HTML Form class to get access to the HTML <form> element on the server.
This class inherits the HtmlControl class.

Lets take an example

The Html Form class can be used to access the HTML <form> elements in the code file
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Submit1_ServerClick(Object Sender, EventArgs e)
    {
        ename.InnerHtml = Text1.Value.ToString();
        fsub.InnerHtml = Text2.Value.ToString();
     
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
Enter Your name: <input id="Text1" type="text" runat ="server" /><br />
   Enter your fav. Subject: <input id="Text2" type="text" runat ="server" /><br />
        <input id="Submit1" type="submit" value="submit" runat ="server" onserverclick ="Submit1_ServerClick" />
        <br />
        Your enter name: <span id="ename" runat="server" /> <br />
        Your Fav. subject <span id="fsub" runat ="server" />

    </div>
    </form>
</body>
</html>


Output
How to access html form element in code file in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top