This is drop down list how to bind in asp.net using C sharp and just create object then pass that drop down id. see the following code step by step.
Step:1

Just create a HTML code like this and then SkinID its not important.
<table><tr><td>  <asp:DropDownList ID="ddlAddCompanyUser" runat="server" SkinID="dropdownlist_large"
                                AutoPostBack="true" OnSelectedIndexChanged="ddlAddCompanyUser_SelectedIndexChanged">
                            </asp:DropDownList></td></tr></table>
Step:2

This code write back end like this and pass the drop down list id and then if u want the selected value for some further process. just write a OnSelectedIndexChanged get the values. then just the pass the method name in OnLoad_page(){LoadAddCompanyUser()}
private void LoadAddCompanyUser()
    {
        List<Company> objCompanyList = Company.GetAllCompany(); // Company table object
        objCompanyList = objCompanyList.OrderBy(c => c.CompanyName).ToList();
        
        ddlAddCompanyUser.Items.Clear();
        ddlAddCompanyUser.DataSource = objCompanyList;
        Utility.BindDropDownList(ddlAddCompanyUser, "CompanyName", "CompanyID", "-------- Select Company -------");
    }
Step:3
Its using for get the value while the select value.
protected void ddlAddCompanyUser_SelectedIndexChanged(object sender, EventArgs e)
    {
  string CompanyName=(ddlAddCompanyUser.SelectedItem.Value));
    }
Read more ...

code is creating drop down menu using JavaScript. I can also used this code its working correctly. Its may be useful.

Step:1

Click here to download the jquery file.

<script type="text/javascript" src="JS/jquery.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
 
 // This hides the menu when the page is clicked anywhere other than the menu.
  $(document).bind('click', function(e) {
   var $clicked = $(e.target);
      if (! $clicked.parents().hasClass("menu")){
          $(".menu dd ul").hide();
    $(".menu dt a").removeClass("selected");
   }

  });
  
  $(".menu dt a").click(function() {

   var clickedId = "#" + this.id.replace(/^link/,"ul");

          // Hides everything else that the current menu 
   $(".menu dd ul").not(clickedId).hide();

          //Toggles the menu.
   $(clickedId).toggle();

          //Add the selected class.
   if($(clickedId).css("display") == "none"){
    $(this).removeClass("selected");
   }else{
    $(this).addClass("selected");
   }

  });
  
// This function shows which menu item was selected in corresponding result place
  $(".menu dd ul li a").click(function() {
   var text = $(this).html();
   $(this).closest('dl').find('.result').html(text);
      $(".menu dd ul").hide();
  });

  
 });
</script>

Step:2

Its CSS class using this class and change the images and image path.


<style type="text/css">

 .menu dl{ margin-left:5px; }
 .menu dd, .menu dt, .menu ul 
 { margin:0px; padding:0px; }
 .menu dd { position:relative; }

 
 .menu dt a {background:#EEEEEE 
 url(Images/privacyOff.png) no-repeat scroll right center;
  display:block; width:40px; height:22px; cursor:pointer;}

 .menu dt a.selected{
  background:#EEEEEE url(Images/privacyOn.png) 
  no-repeat scroll right center;
 }
 .menu dt a span {
 cursor:pointer; display:block; padding:5px;}

 .menu dd ul { 
 background:#EEEEEE none repeat scroll 0 0; display:none;
  list-style:none; padding:3px 0; position:absolute;
  left:0px; width:160px; left:auto; right:0; 
  border:1px solid #656565; cursor:pointer;
  }
 .menu dd ul li{ 
 background-color:#EEEEEE; margin:0; width:160px;
 }
 .menu span.value { display:none;}
 .menu dd ul li a { 
 display:block; font-weight:normal; width:137px; 
 text-align:left; overflow:hidden; padding:2px 4px 3px 19px; 
 color:#111111; text-decoration:none;
 }
 .menu dd ul li a:hover{ 
 background:#656565; color:white; text-decoration:none; 
 }
 .menu dd ul li a:visited{ 
 text-decoration:none; 
 }
</style>


Step:3 

 Its a HTML code just code and past change some thing in your drop down menu list.

<html><head>
</head>

<body>
<div style="clear:both;">.</div>
 <div style="width:500px; margin:auto;">
  <h1 style="margin:20px 0;">Facebook menu Menus</h1>

 <div style="height:300px;">
   <div style="width:162px;">
       <dl style="" class="menu">
          <dt>
       <a class="" id="linkglobal" 
       style="cursor: pointer;"></a></dt>
     <dd>
               <ul style="display: none;" id="ulglobal">
                   <li><a href="#">My Account</a></li>
                   <li><a href="#">My Profile</a></li>
                   <li><a href="#">My Product</a></li>
                   <li><a href="#">My Feature</a></li>
             </ul>
          </dd>
       </dl>
   </div>
 </div>
  </div>
</body></html>
Output:
Read more ...


This function password mode set "Readonly" using Javascript function. I have used.When I try to edit password that time will show the text mode and editable otherwise that text are "Readonly".


<input type="text" id="mytextbox" value="click the button below."/>
<input type="button" value="click" onclick="changeText();"/>

function changeText(){
   var text_box = document.getElementById('mytextbox');
    if(text_box.hasAttribute('readonly')){   
        text_box.value = "This text box is editable.";
        text_box.removeAttribute('readonly');
    }else{       
        text_box.value = "This text box is read only.";
        text_box.setAttribute('readonly', 'readonly');   
    }
}
Read more ...

check Password Strength using Jquery in asp.net:
Password strength checking is an easy way to show the strength of user password on the registration forms. It helps users to choose more secure password when filling the forms.

The idea is that every time a user enters a character, the contents is evaluated to test the strength of the password they have entered... I'm sure everyone has seen these before.


That’s all. Here’s the full jQuery code:


<link href="FormValidation.css" rel="stylesheet" type="text/css" />
    <link href="jquery.validate.password.css" rel="stylesheet" type="text/css" />
    <script src="JS/jquery.js" type="text/javascript"></script>
    <script src="JS/jquery.validate.js" type="text/javascript"></script>
    <script src="JS/jquery.validate.password.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    
    
     $(document).ready(function() {
         // validate signup form on keyup and submit
         var validator = $("#divCreateNewUser").validate({
             rules: {
                 username: {
                     required: true,
                     minlength: 2
                 },
                 txtPassword: {
                     password: "#username"
                 },
                 password_confirm: {
                     required: true,
                     equalTo: "#password"
                 },
                 location: {
                     required: true
                 }
             },
             messages: {
                 username: {
                     required: "Enter a username",
                     minlength: jQuery.format("Enter at least {0} characters")
                 },
                 password_confirm: {
                     required: "Repeat your password",
                     minlength: jQuery.format("Enter at least {0} characters"),
                     equalTo: "Enter the same password as above"
                 },
                 location: {
                     required: "Enter a Location"
                 }
             },
             // the errorPlacement has to take the table layout into account
             errorPlacement: function(error, element) {
                 error.prependTo(element.parent().next());
             },
             // set this class to error-labels to indicate valid fields
             success: function(label) {
                 // set &nbsp; as text for IE
                 label.html("&nbsp;").addClass("checked");
             }
         });
     });
</script>




<body>
    <form id="signupform1" runat="server">
    <div id="signupwrap" runat="server">
    <table align="center">
    <tr>
    <td></td>
    <td><b>User Registration</b></td>
    <td></td>
    </tr>
    <tr>
    <td align="right" class="label">UserName:</td>
    <td  class="field"><asp:TextBox ID="username" runat="server"/></td>
     <td class="status"></td>
    </tr>
    <tr>
    <td  align="right" class="label">Password:</td>
    <td  class="field"><asp:TextBox ID="txtPassword" runat="server" TextMode="Password"/></td>
     <td class="status" align="left">
     <div class="password-meter">
        <div class="password-meter-message">&nbsp;</div>
        <div class="password-meter-bg">
         <div class="password-meter-bar"></div>
        </div>
       </div>
     </td>
    </tr>
    <tr><td align="right" class="label">Confirm Password:</td>
    <td  class="field"><asp:TextBox ID="password_confirm" runat="server" TextMode="Password"/></td>
     <td class="status"></td>
    </tr>
   <tr>
    <td align="right" class="label">Location:</td>
    <td  class="field"><asp:TextBox ID="location" runat="server"/></td>
     <td class="status"></td>
    </tr>
    <tr>
    <td></td>
    <td><asp:Button ID="btnSubmit" Text="Submit" runat="server" 
            onclick="btnSubmit_Click" /></td>
     <td></td>
    </tr>
    <tr>
    <td colspan="3" height="20px">
    </td>
    </tr>
    <tr>
    <td></td>
    <td colspan="2">
    
        <table>
   <tr>
   <td>UserName:</td>
   <td><asp:Label ID="lbluser" runat="server"/></td>
   </tr>
   <tr>
   <td>Password:</td>
   <td><asp:Label ID="lblPwd" runat="server"/></td>
   </tr>
    <tr>
   <td>Location:</td>
   <td><asp:Label ID="lblLocation" runat="server"/></td>
   </tr>
    </table>
    </td>
    
    </tr>
    </table>
    </div>
    </form>
</body>
 
download: click here to download the source code for jquery password strength indicator.

Out-put of the above code 


Read more ...

A script that used to add two textbox values using jQuery:

This is the sample code for add two textbox values and display in one text box buy using jquery:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">

        $(function () {

            var textBox1 = $('input:text[id$=TextBox1]').keyup(foo);

            var textBox2 = $('input:text[id$=TextBox2]').keyup(foo);      

            function foo() {

                var value1 = textBox1.val();

                var value2 = textBox2.val();              

                var sum = add(value1, value2);

                $('input:text[id$=TextBox3]').val(sum);

            }

            function add() {

                var sum = 0;

                for (var i = 0, j = arguments.length; i < j; i++) {

                    if (IsNumeric(arguments[i])) {

                        sum += parseFloat(arguments[i]);

                    }

                }
                return sum;
            }
            function IsNumeric(input) {

                return (input - 0) == input && input.length > 0;
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table width="300px" border="1" style="border-collapse:collapse;background-color:#E8DCFF">
    <tr>
        <td>Butter</td>
        <td> <asp:TextBox runat="server" ID="TextBox1"></asp:TextBox></td>
    </tr>
    <tr>
        <td>Cheese</td>
        <td> 
    <asp:TextBox runat="server" ID="TextBox2"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>Total</td>
        <td>
    <asp:TextBox runat="server" ID="TextBox3"></asp:TextBox>
        </td>
    </tr>
    </table> 
    </div>    </form>
</body>
</html>

Output:


Read more ...

Scrollbar Colors customization                                         It's uncertain how many browsers are still supporting color scrollbars. I understand IE only supported it for one version, then dropped it with the next. However we will keep the code here for those who wish to learn from it. Add the following script within your head tag and change the color attributes to suit.

<style type="text/css">
body { scrollbar-arrow-color: ffffff; scrollbar-base-color:ffffff; scrollbar-dark-shadow-color: ffffff; scrollbar-track-color: ffffff; scrollbar-face-color: ffffff; scrollbar-shadow-color: ffffff; scrollbar-highlight-color: ffffff; scrollbar-3d-light-color: ffffff; }
</style>
Read more ...

This is one of the method to Change font color "onMouseOver" and "onMouseOut" using(CSS)

<style type="text/css">
<html>
<!-- Created on: 27/09/2012 -->
<head>
  <title></title>
</head>
<body>
 <table onmouseover="document.style.x.color='white'"  border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#008080" width="100%" height="34" bgcolor="#95BED4">
      <tr>
        <td onMouseOver="this.style.backgroundColor='#2172A1';  this.style.cursor='hand';" onMouseOut="this.style.backgroundColor='#95BED4'" width="20%">
         <!-- <P> tag onMouseOver Color -->
  <p align="center"><b><font face="Verdana" color="#2172A1" onmouseover="this.style.color='white'" onmouseout="this.style.color='#2172A1'" size="2">Home</font></b></td>
      </tr>
    </table>
</body>
</html></style>

you can do it like this: make two classes in your stylesheet something like menuon and menuoff.

<style type="text/css">
td.menuon { background-color: #000000; color: #FFFFFF; }
td.menuoff { background-color: #FFFFFF; color: #000000; }
</style>

<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
</td>

<a href="#" style="text-decoration: none;" onmouseover="this.style.textDecoration = 'underline'" onmouseout="this.style.textDecoration = 'none'">asdasdasdads</a>


<p onMouseOut="this.style.color = 'black';" onMouseOver="this.style.color = 'red';" align="justify">
Your text here to change text on mouseover</p>
Read more ...

This is one of the method to set mouse pointer focus in page load  on first text-box or
dropdownlist. 

Page.ClientScript.RegisterStartupScript(this.GetType(), "Setfocus", "document.getElementById('" +ddlCountry.ClientID+"').focus();", true);


Read more ...

Create log file in asp.net using C# :
                                                                                        Dot net have  various classes to create, write  on a text file . Here I'm using create() method to create a text file and using some classes to reading and writing text files those are TextReader,StreamReader,StreamWriter,TextWriter classes.These are abstract classes .Here i have taken a logfilepath which is the physical path of the text file.If the file is existing in path then we will write (log) messages into this text file.If the file is not existing in the path then we will create a file in this path and write a message into it 
public static string strPath = AppDomain.CurrentDomain.BaseDirectory;
public static string strLogFilePath = strPath + @"log\log.txt";
public static void WriteToLog(string msg)
 {
  try
   {
    if (!File.Exists(strLogFilePath))
       {
       File.Create(strLogFilePath).Close();
       }
    using (StreamWriter w = File.AppendText(strLogFilePath))
       {
        w.WriteLine("\r\nLog: ");
        w.WriteLine("{0}",DateTime.Now.ToString(CultureInfo.InvariantCulture));
        string err = "Error Message:" + msg;
        w.WriteLine(err);
        w.Flush();
        w.Close();
       }
   }

Read more ...

Textarea - output not showing linebreaks:
        Whitespace in HTML output, including many white-space characters in a row,is displayed in HTML pages as a single  ordinary space. And a line break also considered as whitespace.
If you want to display text that includes linebreaks in HTML so that the linebreaks show, you can do the following ways
  •  Put the text in between <pre> and </pre> tags.
  • (Use your server/client side language to convert the line breaks into <br /> tags.

For example,
Adding Line Breaks into Text Area using JavaScript:

var strAddress= document.forms[0].txt.value;
text = strAddress.replace(/\n\r?/g, '<br />');

Adding Line Breaks into Text Area using PHP:

$strAddress = str_replace("<br>", "\n", $strAddress);
Read more ...

Check Password Strength with JavaScript and Regular Expressions:
This post is  good example of a Password Strength checker that uses JavaScript and Regular Expressions. It check the following conditions to create secure password.
  • The password must contains greater than 6 character
  • The password must have both lower and uppercase characters
  • The password must have at least one number
  • The password must have at least one special character
   PasswordStrength.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  
    <title>Dotnetcluster-Password strength checker</title>
<!-- http://dotnetcluster.blogspot.in -->
    <script language="javascript" type="text/javascript">
 
function pwdStrength(password)
{
        var desc = new Array();
        desc[0] = "Very Weak";
        desc[1] = "Weak";
        desc[2] = "Better";
        desc[3] = "Medium";
        desc[4] = "Strong";
        desc[5] = "Strongest";
        var score   = 0;
        //if password bigger than 6 give 1 point
        if (password.length > 6) score++;
        //if password has both lower and uppercase characters give 1 point      
        if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;
        //if password has at least one number give 1 point
        if (password.match(/\d+/)) score++;
        //if password has at least one special caracther give 1 point
        if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;
        //if password bigger than 12 give another 1 point
        if (password.length > 12) score++;
         document.getElementById("pwdDescription").innerHTML = desc[score];
         document.getElementById("pwdStrength").className = "strength" + score;
}
  
    </script>
</head>
<body>
    <table>
        <tr>
            <td>
          
                    Password<input type="password" name="pass" id="pass" onkeyup="pwdStrength(this.value)" />
            </td>
            <td>
                <div id="pwdDescription" style="color: red"">
                    <b>Password</b>
                </div>
            </td>
        </tr>
       
    </table>
</body>
</html>
 Demo for check password strength:
Password
Password
That's all. If this post is useful for you , please share this to your friends. Thanks!
Read more ...

Auto Tab using JavaScript

Posted by Prince | 7:24:00 PM | | 0 comments »

Auto Tab Form Fields using JavaScript:
                   This a simple sample code for auto tab form fields using javascript.  It works in conjunction with the "maxlength" attribute of HTML, triggered whenever the user's input reaches the maxlength's value.
Code:

<script type="text/javascript">
/*
Auto tabbing script http://dotnetcluster.blogspot.in/
*/
function autoTab(current,next){
if (current.getAttribute&&current.value.length==current.getAttribute("maxlength"))
next.focus()
}

</script>

<b>Enter your input:</b>
<form name="fromAutoTab">
<input type="text" name="first" size="4" onkeyup="autoTab(this, document.fromAutoTab.second)"
    maxlength="3" />
<input type="text" name="second" size="4" onkeyup="autoTab(this, document.fromAutoTab.third)"
    maxlength="3" />
<input type="text" name="third" size="5" maxlength="4" />
</form>
  Try this demo:
  Enter your input:

Read more ...

Check username availability using ajax style in ASP.NET:
                                                Here I'm checking the username availability  with SQL Server 2005. Here you can download  a sample project that explained to check username availability.In this sample I'm checking username using sql server at the onClick event. And also i'm used three images to represent the status of the user name (In-Progress, UserName Already Exists and UserName Available) see the below images. A please wait progress bar running after click the Check Availability button



If the given user name(vasanth) already exists in the database I've displayed the "UserName Already Exists" image.


The given user name(vasanth) already exists in the database, so we have check with some other username (here dotnetcluster). If the given user name(  dotnetcluster ) not exists in the database I've displayed the "UserName Available" image.


 You can download full code for check username availability using asp.net (c#) here. Just download and create  a virtual directory.(Before, you have create a database by using UserAvailability_SQL.txt)
Read more ...

Login failed for user ‘sa’. The user is not associated with a trusted SQL Server connection.(Microsoft SQL Server error: 18456):
                        Normally if the  SQL Server is not set to use both SQL Server and Windows Authentication Mode, this error will occurred. To fix this issue you have to change the Authentication Mode of the SQL server from “Windows Authentication Mode (Windows Authentication)” to “Mixed Mode (Windows Authentication and SQL Server Authentication)”.




Solution:

  1.      Go to Start > Programs > Microsoft SQL Server 2005 > SQL Server Management Studio.
  2.      Right-click the Server name. Select Properties > Security.
  3.      Under Server Authentication, select SQL Server and Windows Authentication Mode   (refer the   screenshot below)
  4.     The server must be stopped and re-started before this will take effect.
                                 
            
Read more ...

Getting the Identity of the last Inserted row - ASP.net/C#:

                                    The key to @@Identity is that it returns the value of an autoincrement column that is generated on the same connection.
           The Connection object used for the Insert query must be re-used without closing it and opening it up again. Access doesn't support batch statements, so each must be run separately. It is also therefore possible, though not necessary, to create a new Command object to run the Select @@Identity query. The following code shows this in action where the Connection object is opened, then the first query is executed against cmd using ExecuteNonQuery() to perfom the Insert, followed by changing the CommandText property of cmd to "Select @@Identity" and running that.
Code:

protected void btnSave_Click(object sender, EventArgs e)
    {
        string strConnection = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        SqlConnection sqlConn = default(SqlConnection);
        SqlCommand sqlCmd = default(SqlCommand);
        try
        {
            string query2 = "Select @@Identity";
            sqlConn = new SqlConnection(strConnection);
            sqlCmd = new SqlCommand("INSERT into student (firstname, lastname, street, city, state) VALUES ('" + txtFirstname.Text + "', '" + txtLastname.Text + "', '" + txtStreet.Text + "','" + txtCity.Text + "','" + txtState.Text + "')", sqlConn);
            sqlConn.Open();
            sqlCmd.ExecuteNonQuery();
            sqlCmd.CommandText = query2;
            int idx = Convert.ToInt32(sqlCmd.ExecuteScalar());
            if (idx != 0)
            {
                Response.Write("<script>alert('Successfully saved')</script>");
            }
            else
                Response.Write("<script>alert('Not saved')</script>");
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString() + "<br>");
        }
        finally
        {
            sqlConn.Close();
        }
    }
Please share this post if it's useful to you. Thanks!.
Read more ...

Remove Duplicate Rows from a Table in SQL Server:
                    Duplication rows in database tables will exists by running the data repeatedly With out  having the primary key on table. Here is an example to remove the duplicate records  from a table in SQL Server

                             

DELETE FROM Employee emp1 WHERE ROW_NUMBER()<>(SELECT MIN( ROW_NUMBER())FROM       EMployee emp2 WHERE emp1.empname= emp2.empname) 

Please share this post if it's useful to you. Thanks!.
Read more ...

Create log file in asp.net using C#:
                                       .NET have a various classes to create, write  on a text file which are file .Here I'm using create() method to create a text file and using some classes to reading and writing text files those are TextReader,StreamReader,StreamWriter,TextWriter classes.These are abstract classes .Here i have taken a logfilepath which is the physical path of the text file.If the file is existing in path then we will write message into this text file.If the file is not existing in the path then we will create a file in this path and write a (log) messages into it

                         
Code:

public static string strPath = AppDomain.CurrentDomain.BaseDirectory;
public static string strLogFilePath = strPath + @"log\log.txt";
public static void WriteToLog(string msg)
 {
  try
   {
    if (!File.Exists(strLogFilePath))
       {
       File.Create(strLogFilePath).Close();
       }
    using (StreamWriter w = File.AppendText(strLogFilePath))
       {
        w.WriteLine("\r\nLog: ");
        w.WriteLine("{0}",DateTime.Now.ToString(CultureInfo.InvariantCulture));
        string err = "Error Message:" + msg;
        w.WriteLine(err);
        w.Flush();
        w.Close();
       }
   }
Please share this post if it's useful to you. Thanks!.
Read more ...

Related Posts Plugin for WordPress, Blogger...