Guest User

Untitled

a guest
Jun 11th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.02 KB | None | 0 0
  1. <form><tablestyle="width:66%;"><tr><td><asp:LabelID="lblmsg"Text="President Election Form : Choose your president"runat="server"/></td></tr><tr><td>            Candidate:</td><td><asp:DropDownListID="ddlcandidate"runat="server"style="width:239px"><asp:ListItem>Please Choose a Candidate</asp:ListItem><asp:ListItem>M H Kabir</asp:ListItem><asp:ListItem>Steve Taylor</asp:ListItem><asp:ListItem>John Abraham</asp:ListItem><asp:ListItem>Venus Williams</asp:ListItem></asp:DropDownList></td><td><asp:RequiredFieldValidatorID="rfvcandidate"runat="server"ControlToValidate="ddlcandidate"ErrorMessage="Please choose a candidate"InitialValue="Please choose a candidate"></asp:RequiredFieldValidator></td></tr><tr><td>            House:</td><td><asp:RadioButtonListID="rblhouse"runat="server"RepeatLayout="Flow"><asp:ListItem>Red</asp:ListItem><asp:ListItem>Blue</asp:ListItem><asp:ListItem>Yellow</asp:ListItem><asp:ListItem>Green</asp:ListItem></asp:RadioButtonList></td><td><asp:RequiredFieldValidatorID="rfvhouse"runat="server"ControlToValidate="rblhouse"ErrorMessage="Enter your house name"></asp:RequiredFieldValidator><br/></td></tr><tr><td>            Class:</td><td>
  2. <asp:TextBoxID="txtclass"runat="server"></asp:TextBox></td><td><asp:RangeValidatorID="rvclass"runat="server"ControlToValidate="txtclass"ErrorMessage="Enter your class (6 - 12)"MaximumValue="12"MinimumValue="6"Type="Integer"></asp:RangeValidator></td></tr><tr><td>            Email:</td><td><asp:TextBoxID="txtemail"runat="server"style="width:250px"></asp:TextBox></td><td><asp:RegularExpressionValidatorID="remail"runat="server"ControlToValidate="txtemail"ErrorMessage="Enter your email"ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td></tr><tr><td><asp:ButtonID="btnsubmit"runat="server"onclick="btnsubmit_Click"style="text-align: center"Text="Submit"style="width:140px"/></td></tr></table><asp:ValidationSummaryID="ValidationSummary1"runat="server"DisplayMode="BulletList"ShowSummary="true"HeaderText="Errors:"/></form>The code behind the submit button:protectedvoid btnsubmit_Click(object sender,EventArgs e){if(Page.IsValid){      lblmsg.Text="Thank You";}else{      lblmsg.Text="Fill up all the fields"
  3.  
  4.  
  5. ====================================
  6.  
  7.  
  8.  
  9. What is IsPostBack?      
  10.  
  11. Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a post back.
  12.  
  13. This is false when the first time the page is loaded and is true when the page is submitted and processed.
  14.  
  15. What is ViewState?
  16.  
  17. A web application is stateless. That means that a new instance of a page is created every time when we make a request to the server to get the page and after the round trip our page has been lost immediately. It only happens because of one server, all the controls of the Web Page is created and after the round trip the server destroys all the instances. So to retain the values of the controls we use state management techniques.
  18.  
  19.  
  20. State Management Techniques
  21.  
  22.  
  23. They are classified into the following 2 categories:
  24.  
  25.  
  26.  
  27.  
  28.  
  29. View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post-back.
  30.  
  31.  
  32. Eg:
  33.  
  34.  
  35.  
  36. // this is a code for submit button  
  37.  
  38. protectedvoid Button1_Click(object sender, EventArgs e)    
  39.  
  40. {    
  41.  
  42. //Value of Textbox1 and TectBox2 is assigin on the ViewState    
  43.  
  44. ViewState["name"]= TextBox1.Text;    
  45.  
  46. ViewState["password"]= TextBox2.Text;    
  47.  
  48. //after clicking on Button TextBox value Will be Cleared    
  49.  
  50. TextBox1.Text= TextBox2.Text=string.Empty;    
  51.  
  52. }    
  53.  
  54.  
  55.  
  56. // this is a code for restore button, to restore the previous content after clicking the submit button  
  57.  
  58. protectedvoid Button3_Click(object sender, EventArgs e)    
  59.  
  60. {    
  61.  
  62. //If ViewState Value is not Null then Value of View State is Assign to TextBox    
  63.  
  64. if(ViewState["name"]!=null)    
  65.  
  66. {    
  67.  
  68. TextBox1.Text= ViewState["name"].ToString();    
  69.  
  70. }    
  71.  
  72. if(ViewState["password"]!=null)    
  73.  
  74. {    
  75.  
  76. TextBox2.Text= ViewState["password"].ToString();    
  77.  
  78. }    
  79.  
  80. }   
  81.  
  82.  
  83.  
  84.  
  85.  
  86. ** go through all properties of login control of  Asp .Net  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. Sample code for creating webpage with login control. In this code it will authenticate with your username and password stored in the database.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. using System;
  105.  
  106. using System.Collections.Generic;
  107.  
  108. using System.Linq;
  109.  
  110. using System.Web;
  111.  
  112. using System.Web.UI;
  113.  
  114. using System.Web.UI.WebControls;
  115.  
  116. using System.Data;
  117.  
  118. using System.Data.OleDb;
  119.  
  120.  
  121.  
  122. namespace WebApplication3
  123.  
  124. {
  125.  
  126.     public partial class WebForm1 : System.Web.UI.Page
  127.  
  128.     {
  129.  
  130.         protected void Page_Load(object sender, EventArgs e)
  131.  
  132.         {
  133.  
  134.             if (!this.IsPostBack)
  135.  
  136.  
  137.  
  138.                 ViewState["LoginErrors"] = 0;
  139.  
  140.         }
  141.  
  142.         /*this is the function which will call at the time of login ,  
  143.  
  144.          * here you can write the code for checking the login username and password */
  145.  
  146.         protected void Login2_Authenticate(object sender, AuthenticateEventArgs e)
  147.  
  148.         {
  149.  
  150.             if (ValidationFunction(Login2.UserName, Login2.Password))
  151.  
  152.             {
  153.  
  154.                 Login2.Visible = false;
  155.  
  156.                 Label1.Text = "login successful";
  157.  
  158.             }
  159.  
  160.             else { e.Authenticated = false; }
  161.  
  162.         }
  163.  
  164.         // this is a user defined function which i am using to check for the username and password in database  
  165.  
  166.  
  167.  
  168.         private bool ValidationFunction(string Username, string Password)
  169.  
  170.         {
  171.  
  172.             bool returnvalue = false;
  173.  
  174.             string strConnection = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\lenovo\\Documents\\Database21.mdb";
  175.  
  176.  
  177.  
  178.             OleDbConnection con = new OleDbConnection(strConnection);
  179.  
  180.             string query = "select Uname, Password from Table1";
  181.  
  182.             OleDbCommand command = new OleDbCommand(query, con);
  183.  
  184.             OleDbDataReader dr;
  185.  
  186.             con.Open();
  187.  
  188.             dr = command.ExecuteReader();
  189.  
  190.             while (dr.Read())
  191.  
  192.             {
  193.  
  194.                 if ((Username == dr["Uname"].ToString()) & (Password == dr["Password"].ToString()))
  195.  
  196.                 {
  197.  
  198.                     returnvalue = true;
  199.  
  200.                 }
  201.  
  202.                 dr.Close();
  203.  
  204.                 return returnvalue;
  205.  
  206.             }
  207.  
  208.             return returnvalue;
  209.  
  210.         }
  211.  
  212.         // this is teh function to check for the password error ,  
  213.  
  214.         //in this code it will allow only  3 time attempt to enter the wrong password  
  215.  
  216.         protected void Login2_LoginError(object sender, EventArgs e)
  217.  
  218.         {
  219.  
  220.             if (ViewState["LoginErrors"] == null)
  221.  
  222.  
  223.  
  224.                 ViewState["LoginErrors"] = 0;
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.             int ErrorCount = (int)ViewState["LoginErrors"] + 1;
  233.  
  234.  
  235.  
  236.             ViewState["LoginErrors"] = ErrorCount;
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.             if ((ErrorCount > 3) && (Login2.PasswordRecoveryUrl != string.Empty))
  245.  
  246.  
  247.  
  248.                 Response.Redirect(Login2.PasswordRecoveryUrl);
  249.  
  250.  
  251.  
  252.         }
  253.  
  254.     }
  255.  
  256. }
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.     Create a website for the multifest organizing in your campus. For the first time the user should register with their information (name, rollnumber, course, semester, mailid, phonenumber, password, confirm password).
  265.  
  266.     After registration they can login with their email id and password.  
  267.  
  268.     Provide update privilege after login  
  269.  
  270.        
  271.  
  272.     Validate phone number field using regular expression validator  
  273.  
  274.     Validate the semester field with range validator (allows only 1 to 8 semeter)
Add Comment
Please, Sign In to add comment