Friday, February 21, 2014

Setting focus of control , immediately when the Ajax Modal Popup Open.

When we want to set the focus of say Textbox when the popup opens use setTimeout() method.

We normally set the focus in this way(this will not work):

 function showmodalpopup(){
       var mpePopup=$find("<%ModalPopupID"%>);
       mpePopup.show()
       $("#txtID").focus();
}

But this will not work if we want to set focus of textbox immediately  when the Modal Popup opens because the control(Textbox) is not render.So $("#txtID") will give us null value.

Lets work with this:


  • Use setTimeout() method
  • It will delay the method in milliseconds 


 function showmodalpopup(){
       var mpePopup=$find("<%ModalPopupID.ClientID"%>);  
       mpePopup.show()
       setTimeout(txtsetfocus(),100);          //time is in milliseconds
}
function txtsetfocus(){
    $("#txtID").focus();
}

Getting Telerik Control Object which is in Item Template.

 

 

 Lets consider that your RadComboBox is in ItemTemplate.

 So here $find(<%=RadComboxID.ClientID%>); will not work as the control is in item template.

  1. We need to first find the radcombobox
  2. Get the id of it
  3. And then use it with $find()
  4. Now you can use the inbuilt telerik methods on the object of radcombobox
  var RadComboxID= $("[id$='RadComboxID']").attr("id");
  var objradcombobox=$find(RadComboxID);            //Here you got the object of RadComboBox 
  objradcombobox.get_selectedvalue();   //use telerik methods with radcombox object

Getting Today's Date in Jquery/Javascript:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
    dd = '0' + dd;
}
if (mm < 10) {
    mm = "0" + mm;
}
today = dd + ':' + mm + ':' + yyyy;
console.log(today);

Objects created of same control(element) are not same

Html control

<input id="test" type="text" />

Script starts from here

var obj1=$("#test");
var obj2=$("#test");
console.log(obj1==obj2);
if(obj1==obj2){ //this will be always false
    console.log(true);
}