Tuesday, March 25, 2014

Access Property in Jquery/Javascript

Public Property Declared in .cs file

 Public Property PId() As Integer
            Get
                Return _PId
            End Get
            Set(ByVal value As Integer)
                _PId= value
            End Set
        End Property


 Public Property LocationID () As Integer
            Get
                Return _LocationID
            End Get
            Set(ByVal value As Integer)
                _LocationID = value
            End Set
        End Property

Note:-To access property it should be declared as Public

Access property in Jquery/Javascript:

 var PatientID = eval('<%= PId%>');
 var LocationID = eval('<%=LocationID %>');

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