Recall your basic coding(Basic Controls) asp .net

Recall your basic coding(Basic Controls) asp .net

Hello Developers!

After a long time, I am posting a .net post. Here is a project sample which includes all the basic controls of asp .net using c# scripting language.

The basic controls included in projects are:

  1. Label control for labeling and showing messages(Error and response)
  2. Text control to accept input in string format\
  3. Radiobutton control to select option among some existing options
  4. Dropdownlist control to select option among existing options but in list view which has compact view
  5. Button Control to accept and reflect the response from user

And here I also mentioned some basic html tag like <table>.

Some code snippet (Design View):

<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>
User Name:
</td>
<td>
<asp:TextBox ID=”txtUserName” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID=”txtName” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<asp:TextBox ID=”txtPassword” TextMode=”Password” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Address:
</td>
<td>
<asp:TextBox ID=”txtAddress” TextMode=”MultiLine” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Contact:
</td>
<td>
<asp:TextBox ID=”txtContact” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID=”txtEmail” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
DOB:
</td>
<td>
<asp:TextBox ID=”txtDOB” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td colspan=”2″ align=”center”>
<asp:Button ID=”btnSave” runat=”server” Text=”Save” OnClick=”btnSave_Click” />
<asp:Button ID=”btnCancel” runat=”server” Text=”Cancel” OnClick=”btnCancel_Click” />
</td>
</tr>
<tr>
<td colspan=”2″ align=”center”>
<asp:Label ID=”lblMessage” runat=”server” Text=””></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>

Code snippet (C# Code):

protected void btnSave_Click(object sender, EventArgs e)
{
string UserName = txtUserName.Text;
string Name = txtName.Text;
string Password = txtPassword.Text;
string Address = txtAddress.Text;
string contact = txtContact.Text;
string Email = txtEmail.Text;
DateTime DOB = DateTime.Now.Date;
try
{
DOB = Convert.ToDateTime(txtDOB.Text);
}
catch (Exception ex)
{
lblMessage.Text = “Invalid Date format”;
lblMessage.ForeColor = System.Drawing.Color.Red;
return;
}

lblMessage.Text=”name: “+Name+”<br>User Name: “+UserName+”<br>Password: “+Password+”<br>Address: “+Address+”<br>Contact: “+contact+”<br>DOB: “+DOB.ToString();
lblMessage.ForeColor = System.Drawing.Color.Green;

}
protected void btnCancel_Click(object sender, EventArgs e)
{
txtUserName.Text = “”;
txtName.Text=””;
txtPassword.Text=””;
txtContact.Text=””;
txtEmail.Text=””;
txtDOB.Text=””;
txtAddress.Text = “”;
}

Download the project here.   c# asp .net with basic controls

 

2 Replies to “Recall your basic coding(Basic Controls) asp .net”

Leave a Reply

Your email address will not be published. Required fields are marked *