Thursday 3 November 2016

c# webform 1




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace webform
{
    public partial class _default : System.Web.UI.Page
    {
        int counter = 0;
        string[] cities = new string[] { "calgary", "saskatoon", "toronto", "montreal", "vancouver" };
        protected void Page_Load(object sender, EventArgs e)
        {
           

            if(!IsPostBack)
            {
                Response.Write("this is the first time page loads");
                ux_cities.DataSource = cities;
                DataBind();
            }
            else
            {
                counter++;



                Response.Write("subsequent page write " + counter);
            }
        }

        protected void ux_submit_Click(object sender, EventArgs e)
        {
            var msg = string.Format("{0}: {1} ({2})", ux_full_name.Text, ux_phone.Text, ux_cities.SelectedValue);
            ux_display.Text = msg;
        }
    }
}

------------------------------------------------------------------
default.aspx source
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="webform._default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 141px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server" >
    <div>
 
    </div>
        <table>
            <tr>
                <td><asp:Label ID="Label1" runat="server" Text="full_name"></asp:Label></td>
                <td><asp:TextBox ID="ux_full_name" runat="server"></asp:TextBox></td>
                <td class="auto-style1">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ux_full_name" ErrorMessage="full name required" ForeColor="Red">*</asp:RequiredFieldValidator>
                </td>
            </tr>
             <tr>
                <td><asp:Label ID="Label2" runat="server" Text="phone"></asp:Label></td>
                 <td><asp:TextBox ID="ux_phone" runat="server" ToolTip="111-1111"></asp:TextBox></td>
                 <td class="auto-style1">
                     <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="ux_phone" ErrorMessage="us phone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator>
                 </td>
            </tr>
            <tr>
                <td><asp:Label ID="Label3" runat="server" Text="city"></asp:Label></td>
                 <td><asp:DropDownList ID="ux_cities" runat="server" Width="130px"></asp:DropDownList></td>
                <td class="auto-style1">&nbsp;</td>
            </tr>
             <tr>
                <td colspan="2"><asp:Button ID="ux_submit" runat="server" Text="submit" OnClick="ux_submit_Click" Width="168px" /></td>
            </tr>
        </table>

     

&nbsp;<asp:Label ID="ux_display" runat="server" Text="Label"></asp:Label>
&nbsp;&nbsp;&nbsp;<asp:Button ID="ux_save" runat="server" Text="save" />

        <br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />

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

--------------------------------------------------
web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
    </modules>
  </system.webServer>
</configuration>

-------------------------------------------------------------

No comments:

Post a Comment