In the below mentioned example i've shown a method call a code behind function asynchrously without any post back using jQuery.
First of all lets be clear with the concept of "asynchronous callback"
The web request which are carried out normally are synchronous, i.e. each request waits for a response from the server and then parses it.
In async callback, the request does not wait for the response. Hence there does not occur any postback since we do not get any response from the server.
The resultant code is in xml format hence we need an XMLHttpRequest to parse the request and convert it into its respective HTML.
Okay now enough of theory, lets press F5
If you are totally unaware of jQuery then here is a brief introduction to it:
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
You can get the details or download the jquery file from here.
You need to add the jquery file and give a reference of it to your page to use it.
Prefer the latest version of jquery.min.js file, "min" stands for minimized. Just 55.9 KB in size.
jQuery has an inbuilt method called "load" used to load the data(HTML) into any DOM block element. The syntax for the "load" method is as below:
$("#divData").load("mydatapage.aspx");
For beginners, $ is the jQuery notation for DOM elements.
If you mention "#" inside the $, it means you are looking for an element having its ID "divData"
mydatapage.aspx is your actual code page. This page would contain just the html control you want to render in "divData" control. i.e. If you want a Repeater control inside "divData", you just need to place that repeater control in mydatapage.aspx and do its respective databinding code in page_load event.
Now you need to Render the HTML for the control and write it using Response.Write();
Thats it! Your done with your NOPOSTBACK PAGE REFRESH SCENARIO
This method is must faster than using an Update Panel of AjaxControls in terms of ViewState and performance.
Saturday, June 6, 2009
Find text inside Sql Code
Simple stored procedure used to find text inside other SQL code - great for dependency checking during development.
ALTER PROC __FindText
@query varchar(100)
AS
SELECT DISTINCT name, type
FROM sysobjects so INNER JOIN syscomments sc ON so.id = sc.id
WHERE text LIKE '%' + @query + '%'
ORDER BY name
ASP.NET Gotchas
Below are some useful links that i found and thought of sharing.
.NET Access Modifiers
Convert code from VB <-> C#
ASP.NET Path understanding
File uploading with filesize validation
Fire server side event in javascript
ASP.NET Image Watermark creater
Dummy Credit card numbers to test payment gateway
ASP.NET Validation to check number, alphanumeric, decimal, alphabets etc (all in one script)
Multiple file uploading control with ASP.NET
Best control for multiple file uploading using jQuery
HTML Cheat sheet
Visual Studio 2005 Keyboard Shortcut keys
HTML color codes
Ajax update content every X seconds(banner)
.NET Access Modifiers
Convert code from VB <-> C#
ASP.NET Path understanding
File uploading with filesize validation
Fire server side event in javascript
ASP.NET Image Watermark creater
Dummy Credit card numbers to test payment gateway
ASP.NET Validation to check number, alphanumeric, decimal, alphabets etc (all in one script)
Multiple file uploading control with ASP.NET
Best control for multiple file uploading using jQuery
HTML Cheat sheet
Visual Studio 2005 Keyboard Shortcut keys
HTML color codes
Ajax update content every X seconds(banner)
String Formats for Double
Below are the string formats used in C#
// just two decimal places
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
// max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
// at least two digits before decimal point
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567); // "23.5"
String.Format("{0:00.0}", 3.4567); // "03.5"
String.Format("{0:00.0}", -3.4567); // "-03.5"
//Thousands seperator
String.Format("{0:0,0.0}", 12345.67); // "12,345.7"
String.Format("{0:0,0}", 12345.67); // "12,346"
//Zero
String.Format("{0:0.0}", 0.0); // "0.0"
String.Format("{0:0.#}", 0.0); // "0"
String.Format("{0:#.0}", 0.0); // ".0"
String.Format("{0:#.#}", 0.0); // ""
//Align numbers with spaces
String.Format("{0,10:0.0}", 123.4567); // " 123.5"
String.Format("{0,-10:0.0}", 123.4567); // "123.5 "
String.Format("{0,10:0.0}", -123.4567); // " -123.5"
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 "
//Custom formatting
String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero"
String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3"
String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3"
How to get ClientID of a control inside a UserControl?
Here is an answer to it,
Below is the code to get the ClientID of any control in the page. The word any is highlighted since it finds the ClientID of a control inside any other control(i.e. usercontrol) too.
function GetClientId(strid)
{
var count=document.forms[0].length;
var i=0;
var eleName;
for (i=0; i <>
{
eleName=document.forms[0].elements[i].id;
pos=eleName.indexOf(strid);
if(pos>=0) break;
}
return eleName;
}
Now you just need to pass your controlname to get its clientId like,
if(GetClientID("txtUserName").value="")
Below is the code to get the ClientID of any control in the page. The word any is highlighted since it finds the ClientID of a control inside any other control(i.e. usercontrol) too.
function GetClientId(strid)
{
var count=document.forms[0].length;
var i=0;
var eleName;
for (i=0; i <>
{
eleName=document.forms[0].elements[i].id;
pos=eleName.indexOf(strid);
if(pos>=0) break;
}
return eleName;
}
Now you just need to pass your controlname to get its clientId like,
if(GetClientID("txtUserName").value="")
Subscribe to:
Posts (Atom)