Friday, December 7, 2012

Reading Text file in Jquery Ajax

First create a dummy text file in your project  named as  text.txt , Now write some text content in that file.
You can read that file through JQuery Ajax request.
Alert will show the text content of written file.

 Code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script>
getTxt = function (){
$.ajax({
url:'test.txt',            // Text file name
success: function (data){
   alert(data);    // or do some other data processing
}
});
}
$(function () {
 getTxt();  // calling ajax function on page load
 });
</script>


======================Update on getting AJAX reponse

AJAX is asyn it doesnt wait for send response.

function getddlData() {
    var ajaxResponse;
    $.ajax({
        type: "POST",
        url: 'TextEditor.aspx/GetBookMarkData',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        cache: false,
        // Text file name
        success: function (response) {
            //    //alert(data.d);    // or do some other data processing
            //   //return data.d;
            ajaxResponse = response;
        }
    });
    return ajaxResponse;

Now you can use it like :

 var response = getddlData();
        alert(response.d); 

Saturday, December 1, 2012

Foreach in a GridView through JQuery

GridView Loop in  JQuery  To find a control


How to disable  a button in grid view in asp.net 

first add reference to JQuery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>  





 <script>
$(function () {
  $('.jqSelector').each(function () {
$(this).attr("disabled", true);
  });
 })
 </script>


Note : jqSelector is a CSS class given to a button control inside the grid view


Use ASP Cookie in aspx

<%if HttpContext.Current.Request.Cookies("authuserid").Value<>"1"  AND HttpContext.Current.Request.Cookies("authuserid").Value<>"24" then%>



'''' User code here
<%End if%>