European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET 5 Hosting - HostForLIFE.eu :: Auto Resize Text Box in ASP.NET

clock December 5, 2014 06:53 by author Peter

In this article, we want to talk about How to to develop a simple Example of text box control with ASP.NET 5. Once we enter data during this text box control we want to the length (re-size height and width) of text box. Text box is an ASP.NET web control, use for obtaining input by user as similar to the login web site we see username and password Textbox exactly in which we enter username and password. Inside the Toolbox we obtain a textbox only drag and drop it on ASP.NET web site and then it is automatically create our html code. We think about a text box and attempt to Auto re-size it once we enter value in text box.

And this is the example code that I used:
JavaScript function for resize ASP.NET control
And here is the Text Box auto resize function.

function resizemultilineTextBox(txt) {
            txt.style.height = "1px";
            txt.style.height = (1 + txt.scrollHeight) + "px";
        }
Asp.net web page code with Textbox:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Autoresizetextboxcontrol.aspx.cs" Inherits="Autoresizetextboxcontrol" %>
<!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">
<head id="Head1" runat="server">
    <title></title>
        <script>
        function resizemultilineTextBox(txt) {
            txt.style.height = "1px";
            txt.style.height = (1 + txt.scrollHeight) + "px";
        }
    </script>
    <style type="text/css">
        .style1
        {
            color: #990000;
            text-decoration: underline;
            font-family: Arial, Helvetica, sans-serif;
        }
    </style>
</head>
<body>
    <form id="form2" runat="server">
        <div align="center" style="height: 123px; background-color: #6699FF">
        <h1 class="style1">Auto Resize ASP.NET TextBox Control</h1>
            <table style="width: 494px">
                <tr>
                    <td>Enter Text Here: </td>
                    <td>                      
                        <asp:TextBox ID="txtDescription" runat="server"                            

onkeyup="resizemultilineTextBox(this)" TextMode="MultiLine" Width="212px">
</asp:TextBox>                      
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>



ASP.NET 5 Hosting - HostForLIFE.eu :: How to create “Remember Me” Login Page using checkbox with ASP.NET ?

clock December 1, 2014 06:12 by author Peter

In this tutorial, I will tell you How to create “Remember Me” Login Page using checkbox with ASP.NET 5 and C#. Whenever you tick Remember Me checkbox it will maintain username and password for web site user using Cookies.

When user click login button that could stores the username and password inside the cookie. First thing you need to do is confirm that the Remember Me checkbox is checked or not, if it's checked then store the username and password inside the cookie to the 1 month and if not checked then set the expiration day to 1 day in else condition to destroy the cookie.

And here is the code that I used:

protected void Page_Load(object sender, EventArgs e)  

      if (!Page.IsPostBack) 
      { 
           if (Request.Cookies["UserName"] != null) 
                txtUserName.Text = Request.Cookies["UserName"].Value; 
           if (Request.Cookies["Password"] != null) 
                txtPassword.Text = Request.Cookies["Password"].Value; 
           if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null) 
                chkRember.Checked = true;  
      }  
}  
protected void btnLogin_Click(object sender, EventArgs e) 
 { 
       string stringconnection = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; 
       MySqlConnection connection = new MySqlConnection(stringconnection); 
      try 
      {  
           int flag = 0; 
           if (chkRember.Checked == true) 
           { 
                Response.Cookies["UserName"].Value = txtUserName.Text; 
                Response.Cookies["Password"].Value = txtPassword.Text; 
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1); 
                Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1); 
           } 
           else 
           { 
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(-1); 
                Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(-1); 
           }  
           MySqlCommand com = new MySqlCommand("select * from tbl_user_details", connection); 
           connection.Open(); 
           if (connection.State == ConnectionState.Open) 
           { 
                MySqlDataReader objSqlDataReader;                
                objSqlDataReader = com.ExecuteReader();

                    while (objSqlDataReader.Read())                 
                     { 
                     if (objSqlDataReader[2].ToString().Equals(txtUserName.Text) && objSqlDataReader[5].ToString().Equals(txtPassword.Text)) 
                     { 
                          flag = 1; 
                          Session["UserName"] = txtUserName.Text; 
                          Session["UserType"] = objSqlDataReader[8].ToString(); 
                          Response.Redirect("ContactUs.aspx", false); 
                     } 
                     else 
                     { 
                          ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); 
                    } 
                } 
           } 
      } 
      catch (Exception ex) 
      { 
           lblMsg.Text = ex.ToString(); 
      } 
      finally  
      { 
           connection.Close(); 
      }
 }



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in