Category Archives: javascript

29 Jun 12
admin
No Comments
selected value of RadCombobox using Javascript

function getValue()  
{  
    var combo = $find(“<%= RadComboBox1.ClientID %>”);  
    alert(combo.get_value());  
}  

JQuery Validation in Asp.Net

30 Mar 11
admin
No Comments
Hai,

Using following steps, you can perform JQuery validation in aspx pages.

Step1: Create a script reference to these files in the head section of your page.

src=”JS/jquery-1.3.2.js” type=”text/javascript”

src=”JS/JQuery.Validate.js” type=”text/javascript”

Step2: Add a textbox and a button inside form tag

Step3: Now add following script inside script tag to enable JQuery Validation

$(document).ready(function() {
$(“#form1”).validate({
rules: {
<%=TextBox1.UniqueID %>: {
minlength: 2,
required: true
}
}, messages: {}
});
});

Step3: Run the application and click on the Submit button. The Validation fires and will display the error message.

If you want to display custom messages, make use of the ‘messages’ parameter to specify a custom error message for a field as shown below:

$(document).ready(function() {
$(“#form1”).validate({
rules: {
<%=TextBox1.UniqueID %>: {
minlength: 2,
required: true
}
}, messages: {
<%=TextBox1.UniqueID %>:{
required: “* Required Field *”,
minlength: “* Please enter atleast 2 characters *”
}}
});
});

Happy Programing…

Selected text of dropdownlist using JQuery

01 Feb 11
admin
one comments
Hi,

We will get selected text of a dropdownlist using JQuery.

syntax:

$(“#myselect :selected”).text();

For an ASP.NET dropdown you can use the following:

$(“[id*=’MyDropDownId’] :selected”).text()

Happy Programing…

Query String using JQuery

28 Jan 11
admin
No Comments
Hai,

We can write an extension for Jquery to get querystring(parameter) values of a url.
Extension of JQuery as follows.

$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf(‘?’) + 1).split(‘&’);
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split(‘=’);
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return $.getUrlVars()[name];
}
});

You need to inclue above code in your JQuery file.You will get querystring(parameter) values of the url using follwing code in your js file.

// Getting URL var by its name
var byName = $.getUrlVar(‘name’);

Happy Programing…

Bind Unbind event in JQuery

22 Nov 10
admin
No Comments
Hai,

We can bind an event using .bind() methode of JQuery.

For example:
$(“#buttonId”).bind(‘onclick’, functionName);
or
$(‘#buttonId).bind(‘click’, function() {
alert(‘User clicked’);
});

Unbinding is done by using .unbind()

Example:

$(“#buttonId”).unbind(‘onclick’);

Happy Programing…

Scroll bowser window to top using JQuery

12 Nov 10
admin
No Comments
Hai,

Using JQuery we can scroll browser window to top position.

$(‘html, body’).animate({ scrollTop: 0 }, ‘fast’);

Happy Programing…

JQuery Date formating

08 Oct 10
admin
No Comments
We can format date using JQuery.

syntax:

$.format.date(“2010-01-12 10:54:50.546”, “dd/MM/yyyy”);

Select radiobuttonlist using jquery

06 Oct 10
admin
one comments
You can select a radiobuttion list by value using jquery

$(‘#radiobuttonlistId’).find(“input[value=’0′]”).attr(“checked”, “checked”);

Regards.

Updatepannel and JQuery

12 Aug 10
admin
No Comments
Hai,

Normaly JQuery won’t work after a partial postback from an update pannel.

Write Sys.Application.add_load(function_name); in content template of update pannel to solve this issue.

Happy Programing….

Checkbox list validation using javascript

11 Aug 10
admin
one comments
function readListControl()
{
var tableBody = document.getElementById(‘<%=Checkboxlist_id%>’).childNodes[0];

for (var i=0;i < tableBody.childNodes.length; i++)
{
var currentTd = tableBody.childNodes[i].childNodes[0];
var listControl = currentTd.childNodes[0];

if (listControl.checked == true)
{
return true;
}
}
alert(“Please select any item!”);
return false;

}