Skip to main content

Posts

Showing posts from September, 2014

Auto Increment column in radgrid

Code : if (e.Item is GridDataItem)         {             int strIndex = radgridshowRRstatus.MasterTableView.CurrentPageIndex;             Label lbl = e.Item.FindControl("lblSn") as Label;             lbl.Text = Convert.ToString((strIndex * radgridshowRRstatus.PageCount) + e.Item.ItemIndex + 1);         }    <telerik:GridTemplateColumn HeaderText="Sr.No" UniqueName="SrNo">                     <ItemTemplate>                         <asp:Label ID="lblSn" runat="server" />                     </ItemTemplate>                 </telerik:GridTemplateColumn> Done :)

Service Broker not working after database restore

There may be a problem when you configure your database with broker and create queue and Services. You may already done with following ALTER DATABASE Chatter SET ENABLE_BROKER CREATE QUEUE ContactChangeMessages; CREATE SERVICE ContactChangeNotifications   ON QUEUE ContactChangeMessages ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]); But even that front end dont works. In this case the problem cannot be solved without knowing reason but there can be a hit in the dark .You can try this ALTER AUTHORIZATION ON DATABASE ::[your database name ] TO [ sa ];. Done :)

:prevUntil jquery traversing example

Code :   <dl>             <dt id="term-1">term 1</dt>             <dd>definition 1-a</dd>             <dd>definition 1-b</dd>             <dd>definition 1-c</dd>             <dd>definition 1-d</dd>             <dt id="term-2">term 2</dt>             <dd>definition 2-a</dd>             <dd>definition 2-b</dd>             <dd>definition 2-c</dd>             <dt id="term-3">term 3</dt>             <dd>definition 3-a</dd>             <dd>definition 3-b</dd>         </dl> Jquery Code :   <script>         $(document).ready(function () {             $("#term-2").prevUntil("dt").css({ backgroundColor: "RED" });             $("#term-3").prevUntil("#term-1", "dt,dd").css({color:"GREEN"});         });     </script> Done :)

Jquery use has traversing to find element

Code:  <ul>             <li>Does the UL contain an LI?</li>         </ul> Jquery :  <style type="text/css">         .full         {             border: 1px solid red;         }     </style>     <script>         $(document).ready(function () {             $("ul").append("<li>"+($("ul").has("li").length?"YES":"NO")+"</li>");             $("ul").has("li").addClass("full");         });     </script> Done :)

Get current time in control parameter in sqldatasource in asp.net

Code:  <asp:SqlDataSource ID="sdsRgResult" runat="server" ConnectionString='<%$ ConnectionStrings:LCODLConnectionString %>'                             SelectCommand="                 Select command HERE  ">                             <SelectParameters>                                 <asp:ControlParameter Name="EntryBy" ControlID="hdnLoginName" />                              <asp:ControlParameter Name="FromDate" ControlID="rdtFromDate" DefaultValue="01-01-1900 00:00:00" />                              <asp:ControlParameter Name="ToDate" ControlID="rdtToDate" DefaultValue= '<% DateTime.Now %>' />                             </SelectParameters>                         </asp:SqlDataSource> Done:)

Redirect to another page in jquery in asp.net

Code :  <script type="text/javascript">         $(document).ready(function () {             $("#SEARCH").click(function () {                               var url = "./Detail.aspx";                 $(location).attr('href', url);             });             $("#ADD").click(function () {                 var url = "./Addnewmenu.aspx";                 $(location).attr('href', url);                          });         });     </script> Done :)

bind dropdownlist with sqlserver column in asp.net

Code :  SqlConnection vcomm = new SqlConnection(connectionstring);         vcomm.Open();         SqlDataAdapter vadap = new SqlDataAdapter("Select DISTINCT Type from Menu", vcomm);         vadap.Fill(tbly);         DropDownList1.DataSource = tbly;         DropDownList1.DataTextField = "Type";         DropDownList1.DataValueField = "Type";         DropDownList1.DataBind();         vcomm.Close(); Done :)

Deleting Row option with deleting file from server and database through gridview

First use gridview :  <asp:GridView ID="grdAcademicResourceFilesView" runat="server" AutoGenerateColumns="False"                             CellPadding="4" DataKeyNames="ID" ForeColor="#333333" GridLines="None" OnRowDeleting="grdAcademicResourceFilesView_RowDeleting"                             Width="100%">                             <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />                             <Columns>                                 <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />                                 <asp:BoundField DataField="Name" HeaderText="Category Name" SortExpression="Name" />                                 <asp:BoundField DataField="ProgramCode" HeaderText="Program Code" SortExpress

Alert message in asp.net

You can use following function as follow :     public void DisplayAJAXMessage(string msg)     {         Control page = this;         string myScript = String.Format("alert('{0}');", msg);         ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);     } DisplayAJAXMessage("hello I am alert");

Asp.net server side check to check file extension uploaded and file size

Here is the code : if (FileUpload1.HasFile)                 {                     if (((System.IO.Path.GetExtension(FileUpload1.FileName)) == ".pdf" || (System.IO.Path.GetExtension(FileUpload1.FileName) == ".zip") || (System.IO.Path.GetExtension(FileUpload1.FileName) == ".rar") || (System.IO.Path.GetExtension(FileUpload1.FileName) == ".xlsx") || (System.IO.Path.GetExtension(FileUpload1.FileName) == ".xls") || (System.IO.Path.GetExtension(FileUpload1.FileName) == ".doc") || (System.IO.Path.GetExtension(FileUpload1.FileName) == ".docx")) && FileUpload1.PostedFile.ContentLength < 20480000)                     {                         check = true;                     }                     else                     {                         check = false;                         if (!((System.IO.Path.GetExtension(FileUpload1.FileName)) == ".pdf" || (System.IO.Path.GetExtension(FileUpload1

Custom validaton to put file size limit in file upload control in asp.net

Use custom validator as follow :-   <asp:CustomValidator ID="NewPasswordCustomValidator" runat="server" Text="File Size Limit exceed !! Only 20 MB is allowed"                                                 ToolTip="FileSize should not exceed 4 MB" ControlToValidate="FileUpload1" ClientValidationFunction="setUplaodButtonState"                                                 Display="Dynamic" ValidationGroup="submit" ErrorMessage="File Size Limit exceed !! Only 20 MB is allowed"></asp:CustomValidator> Then make one javascript function to put limit on size upto 20mb    function setUplaodButtonState(oSrc, args) {             var maxFileSize = 20480000 // 20MB -> 20000 * 1024 //             var fileUplaod = $("#<%=FileUpload1.ClientID %>");             if (fileUplaod.val() == '') {                 args.IsValid = false;             }            

Regular Expression for doc pdf docs xls xlxs rar zip or any Other

For file extension Regular expression can be made very simply. (.*\.([Pp][Dd][Ff])$)  For pdf For two like pdf and zip both (.*\.([Pp][Dd][Ff])|.*\.([Zz][Ii][Pp])$) Like same we can create for all (.*\.([Pp][Dd][Ff])|.*\.([Zz][Ii][Pp])|.*\.([Rr][Aa][Rr])|.*\.([Xx][Ll][Ss][Xx])|.*\.([Xx][Ll][Ss])|.*\.([Dd][Oo][Cc])|.*\.([Dd][Oo][Cc][Xx])$) For pdf zip rar xlsx xls doc docx Can be used in regular expression in file upload control in asp.net as follow :--   <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1"                                                 ErrorMessage="Only .zip, .rar, .xlsx, .xls, .pdf, .doc, .docx files are allowed" ValidationExpression="(.*\.([Pp][Dd][Ff])|.*\.([Zz][Ii][Pp])|.*\.([Rr][Aa][Rr])|.*\.([Xx][Ll][Ss][Xx])|.*\.([Xx][Ll][Ss])|.*\.([Dd][Oo][Cc])|.*\.([Dd][Oo][Cc][Xx])$)"                                                 Display="D

parent empty has contains selector in jquery with code

Parent is just opposite to empty has checks element where as contains checks string Code: <table border="1">             <tr>                 <td>Value 1</td>                 <td>                     <p></p>                 </td>             </tr>             <tr>                 <td>Value 2</td>                 <td></td>             </tr>         </table>         <p>             <span>                 <p>                     hahaha                 </p>             </span>         </p>  <style type="text/css">         td         {             width: 40px;             background: green;         }     </style>  <script type="text/javascript">         $(document).ready(function () {             $("td:parent").fadeTo(1500, 0.33);             $("td:empty").fadeTo(3000, 0.11, function

parent selector in jquery

It works for those elements which has atleat one child Code :     <table border="1">             <tr>                 <td>Value 1</td>                 <td></td>             </tr>             <tr>                 <td>Value 2</td>                 <td></td>             </tr>         </table>  <style type="text/css">         td         {             width: 40px;             background: red;         }     </style>  <script type="text/javascript">         $(document).ready(function () {             $("td:parent").fadeTo(1500,0.33);         });     </script> Done :)

visible and hidden selector in jquery

Code :  <button>Show hidden to see they don't change</button>         <div></div>         <div class="starthidden"></div>         <div></div>         <div></div>         <div style="display: none;"></div>     <style type="text/css">         div         {             width: 50px;             height: 40px;             margin: 5px;             border: 3px outset green;             float: left;         }         .starthidden         {             display: none;         }     </style>  <script type="text/javascript">         $(document).ready(function () {             $("div:visible").click(function () {                 $(this).css("background", "yellow");             });             $("button").click(function () {                              $("div:hidden").show("fast");                 retu

common multiple attributes selectors found in jquery

  $(document).ready(function () {             $("a[hreflang|='en']").css({ border: "3px green dotted" });// attribute prefix with             $("a[hreflang~='en']").css({ border: "3px green dotted" });// attribute contains word             $("input[id][name^='man']").val("I start with man kyword");// attribute starts with             $("input[id][name$='man']").val("I end with man kyword");// attribute ends with             $("input[name*='man']").val("I have man").css({ color: "red" });// attribute containanywhere         }); Done :)

attribute contains selector in jquery

Here is the code  <input name="man-news">         <input name="milkman">         <input name="letterman2">         <input name="newmilk"> and jquery for that is   $(document).ready(function () {                  $("input[name*='man']").val("I have man").css({ color: "red" });         }); Done :)

multiple attribute selector in jquery

Here is the requirement to select all element that has attribute name and id  and both end with 'man' Here is the code :   <input id="man-news" name="man-news">         <input name="milkman">         <input id="letterman" name="new-letterman">         <input name="newmilk"> and jquery for this is : <script type="text/javascript">         $(document).ready(function () {                    $("input[id][name$='man']").val("I end with man kyword");         });     </script> Done :)

attribute contains word selector in jquery

Here is the code :  <a href="example.html" hreflang="en">Some text</a>         <a href="example.html" hreflang="en-UK">Some other text</a>         <a href="example.html" hreflang="english en">will not be outlined</a>         <a href="example.html" hreflang="english enenen">will not be outlined</a>         <a href="example.html" hreflang="english en---">will not be outlined</a> Jquery for that  <script type="text/javascript">         $(document).ready(function () {             //$("ul li:nth-child(2)").append("<span> - 2nd!</span>")             $("a[hreflang~='en']").css({ border: "3px green dotted" });                    }); </script> Done :)

attribute contains prefix selector in jquery

Here is the code : <a href="example.html" hreflang= "en" >Some text</a> <a href="example.html" hreflang=" en -UK">Some other text</a> <a href="example.html" hreflang="english">will not be outlined</a> Here is jquery to handle it     <script type="text/javascript">         $(document).ready(function () {                       $("a[hreflang|='en']").css({ border: "3px green dotted" });                    });     </script> Done :)

Only-child , last child , first-child selector example in jquery

only-child will fetch only those elements that has only one child.for example <div> <button>i am only child</button> </div> <div> <button>I have  brother</button> <button>I have brother</button> </div> For only-child    $("div button:only-child").text("last child").css("border", "2px blue solid "); // for only child Done:))  For last-child  $("div span:last-child")             .css({ color: "red", fontsize: "140%" })             .hover(function () {                 $(this).addClass("solast");             }, function () {                 $(this).removeClass("solast");             }); For first-child  equivalent to nth-child(1)  $("div span:first-child")             .css({ color: "red", fontsize: "140%" })             .hover(function () {                 $(this).addClass("solas

Add hover and unhover in jquery

Suppose there is element on which we want to add class on hover and remove on unhover and all that with jquery then dot eh following code :    <div>             <span>John,</span>             <span>Karl,</span>             <span>Brandon,</span>             <span>Sam</span>         </div>         <div>             <span>Glen,</span>             <span>Tane,</span>             <span>Ralph,</span>             <span>David</span>         </div>  $("span")             .css({ color: "red", fontsize: "140%" })             .hover(function () {                 $(this).addClass("solast");             }, function () {                 $(this).removeClass("solast");             }); and class is as follow :  span.solast         {             text-decoration: line-through;         } Done

Remove Invalid postback or callback argument error in asp.net

If in any case there is problem in asp.net as follow : " Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. " Then just add this at the top of page  <%@ Page ... EnableEventValidation="false" %> Problem solved :)

Use of each function in jquery plugin to concat string with attribute

Suppose We have  <a href="https://solvecode.blogspot.in">dgdfgffgf</a><br /> Its output will be "dgdfgffgf" But What if i want all <a> tags used will have output like its text + href attribute <a href="https://solvecode.blogspot.in">dgdfgffgf</a><br /> Like this - "dgdfgffgf (https://solvecode.blogspot.in)" So for this we can create very simple plugin that can do it easily by using each loop. Here is the code :   <script src="Scripts/jquery-2.1.1.js"></script>     <script src="Scripts/jquery-ui.js"></script> <script type="text/javascript">         $.fn.showlinklocation = function () {             this.filter("a").each(function () {                 var link = $(this);                 link.append(" (" + link.attr("href") + ") ");             });             return this;         };

How to make customizable plug-ins in jquery

Did you ever want to create your own jquery so that users can modify it accordingly they want.So you need to create plugins for that,That are very easy to create and manage. Here is the simple demo code to see  <script src="Scripts/jquery-2.1.1.js"></script>     <script src="Scripts/jquery-ui.js"></script>     <script type="text/javascript">         $.fn.greenify = function (options) { //default values             var settings = $.extend({                 color: "yellow",                 backgroundColor: "black",                 height: "100px",                 width:"100px"             }, options);             return this.css({                 color: settings.color,                 backgroundColor: settings.backgroundColor,                 height: settings.height,                 width:settings.width             })         };         $(document).ready(function ()

Way to create plugin in jquery

Here is the demo code to create simple plugin in jquery :-    $.fn.greenify = function () {                 this.css("background-color", "green");                 this.css("height", "100px");                 this.css("width", "100px");                 this.css("position", "relative");                 this.css("float", "left");                 return this;             }; Above code is used to create one plugin function what can be used anywhere in same project or in different project and can be used in following way:    $(document).ready(function () {                 $("div div").greenify().addClass("greeifiyclass");                         }); Here is one complete demo that shows different way to create plugin :   <script type="text/javascript">         (function ($) {             //user defined functions             $.fn.green

Jquery Clone and Appento function description

Here is a lovely example to explain < div class = "container" > < div class = "hello" > Hello </ div > < div class = "goodbye" > Goodbye </ div > </ div > $( ".hello" ).appendTo( ".goodbye" ); Will result in : < div class = "container" > < div class = "goodbye" > Goodbye < div class = "hello" > Hello </ div > </ div > </ div > AND $( ".hello" ).clone().appendTo( ".goodbye" ); Result in < div class = "container" > < div class = "hello" > Hello </ div > < div class = "goodbye" > Goodbye < div class = "hello" > Hello </ div > </ div > </ div > Done :)