Useful things in jquery

Auto suggest and auto complete in .NET using jquery

(Along with master and content pages implementation).

Master page code:

<head runat="server">
     <link href="StyleSheet.css" rel="stylesheet" runat="server" type="text/css" />
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
     <asp:contentplaceholder id="LocalScripts" runat="server"></asp:contentplaceholder>
 </head>
 <body id="body" runat="server">
     <form id="form1" runat="server" defaultbutton="SignOutLB">
         <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
         </asp:ContentPlaceHolder>
     </form>
 </body>

Content page:

<asp:Content ID="ScriptContent" ContentPlaceHolderID="localScripts" runat="server">
 <script type="text/javascript">
     function suggest(inputString)
     {
         if(inputString.length == 0)
         {
             $('#suggestions').fadeOut();
         }
         else
         {
             $('#AAATB').addClass('load');
             $.post("AutoSuggest.aspx?ST=" + inputString, function(data){
                 if(data.length >0)
                 {
                     $('#suggestions').fadeIn();
                     $('#suggestionsList').html(data);
                     $('#AAATB').removeClass('load');
                 }
             });
         }
     }
     function fill(thisValue)
     {
         $("#<%= ProjNoTB.ClientID %>").val(thisValue);
         setTimeout("$('#suggestions').fadeOut();", 600);
     }
 </script>
</asp:Content>

ASP.NET code:

<asp:TextBox ID="AAATB" runat="server" Width="90px" MaxLength="6" onkeypress="return IsNumberKey(event)" CssClass="textboxStyle" ValidationGroup="projNoValGp" onkeyup="suggest(this.value);" onblur="fill();" />
<div class="suggestionsBox" id="suggestions" style="display: none;">
     <img src="Images/arrow.png" style="position: relative; top: -2px; left: 50px;" alt="" />
     <div class="suggestionList" id="suggestionsList"> &nbsp; </div>
 </div>

sample AutoSuggest.aspx code:

protected void Page_Load(object sender, EventArgs e)
{
     string[] arr = new string[] {
                         "1234",
                         "1111",
                         "1333"
     };
     for (int i = 0; i < 3; i++)
     {
         Response.Write("<li onClick=\"fill(\'" + arr[i] + "\');\">" + arr[i] + "</li>");
     }
}

And my stylesheet will have the following

/* For autocomplete textbox — start */

#AAATB

{

padding:3px;

border:1px#CCCsolid;font-size:17px;

}

.suggestionsBox

{

position: absolute;

left: 130px;

top:42px;

margin: 26px0px0px0px;

width: 100px;

padding:0px;

background-color: #FFEDDD;

border-top: 3pxsolid#000;

color: #000;

border-radius: 3px;

}

.suggestionList

 {

margin: 0px;

padding: 0px;

}

.suggestionList ul li

{

list-style:none;

margin: 0px;

padding: 6px;

border-bottom:1px dotted #666;

cursor: default;

}

.suggestionList ul li:hover

{

background-color: #FC3;

color:#000;

}

ul

 {

font-family:Arial,Helvetica,sans-serif;

font-size:11px;

color:#FFF;

padding:0;

margin:0;

}

.load

{

background-image:url(loader.gif);

background-position:right;

background-repeat:no-repeat;

}

#suggest

 {

position:relative;

}

/* For autocomplete textbox — end */

Now this will bring up the list of values as soon as 1 is typed onto the textbox. It would look as follows

autosuggest img

Advertisements

How to ignore the “–Select–” in a dropdown during validation

The InitialValue helps to ignore the “–Select–” in a dropdown during validation.

<asp:DropDownList ID=”ProjNumDDL” runat=”server” Width=”90px” CssClass=”dropdownStyle”></asp:DropDownList>

<asp:RequiredFieldValidator ID=”ProjNumDDLVal” runat=”server” ErrorMessage=”*” CssClass=”smallTextFont” ControlToValidate=”ProjNumDDL” InitialValue=”–Select–“></asp:RequiredFieldValidator>

Working with windows service

Steps to make a windows service work:

  • Create the windows service as usual.
  • Build the service.
  • Goto command prompt and install the .exe file of the service(present inside the debug folder) using the sc command.
    • sc create [ServiceName] binpath= [exe file path]
  • Goto services -> right click on [ServiceName] and click start.
  • To delete the service the command is
    • sc delete [ServiceName]

Important Note: There is no need to create a separate setup file for this.