Speed up development with full-stack environments for every branch.

Learn More

Submit a Form In ASP.NET

4465 Runs 46476 Views 8112 Copies


mirang 126

published 4 years ago

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <title>Submit a Form In ASP.NET</title>
    <script language="C#" runat="server">
        public void Page_Load(Object sender, EventArgs e)
            //Print the time when the page loaded initially
            Response.Write("The Page Loaded at: " + DateTime.Now.ToLongTimeString());
            //For an ASP.NET form to  be submitted it is mandatory to have the form runat="server" otherwise it will not be submitted when a button is clicked
            //Also when you want to submit a form on button click, just attach the ServerClick event on the button, so that when the button is clicked
            //the form is submitted and the event is handled by the handler
            btnSubmit.ServerClick += new EventHandler(btnSubmit_ServerClick);
        /// <summary>
        /// Button Click Event which is fired when the 'Save' button is clicked and the form is submitted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnSubmit_ServerClick(object sender, EventArgs e)
            divResultSubmitted.InnerHtml = "Value '<b>" + txtCount.Value + "</b>' Successfully Submitted !!!";
    <style type="text/css">
            background-color: #32373a;
            color: #FFFFFF;
            background-color: #FFFFFF;
            height: 100%;
            color: #32373a;
            background-color: #fdd136;
          border-radius:4px 4px 4px 4px;
    <form id="form1" runat="server">
    <div id='mainBody'>
            Submit a Form in ASP.NET
        <br />
        <div id="divGETHTML" runat="server">Enter your number and click on <b>Save</b> to submit the value : 
        <input type="text" maxlength="20" id="txtCount" runat="server" /><input runat="server" type="button" value="Save" class='button' id="btnSubmit" /></div>

        <br /><br />

        <div id="divResultSubmitted" runat="server" />
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).