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%>

Saturday, October 13, 2012

Cross browser : Change scroll bar color & Custom scrollbar

Add the following CSS snippet in the header section of webpage.
 


 <STYLE>/* Let's get this party started */
::-webkit-scrollbar {    width12px;}
 /* Track */::-webkit-scrollbar-track 
{    -webkit-box-shadowinset 6px rgba(0,0,0,0.3);
     -webkit-border-radius10px;    border-radius10px;
}
 /* Handle */
::-webkit-scrollbar-thumb
 {    -webkit-border-radius10px; 
  border-radius10px;    backgroundrgba(255,0,0,0.8)

  -webkit-box-shadowinset 6px rgba(0,0,0,0.5)}
::-webkit-scrollbar-thumb:window-inactive 
{  backgroundrgba(255,0,0,0.4)}    
  </STYLE>

Monday, August 27, 2012

Avoid the ActiveX warning in IE7 and IE8?

Add this to your html page :


 <!doctype html>
<!-- saved from url=(0023)http://www.contoso.com/ -->

Monday, August 13, 2012

Div Scrolling Left and Right Through JQuery




In this example I am creating 2 buttons dynamically on page load through JQuery & We can scroll left & right on click on these 2 buttons

 $(document).ready(function () {

     // Creating two Left Right Scroll Button through JQuery
        var  btnRht= $("<input type='button' id='btnLeft' value='>>' class='ButtonStyle' width='5px' />");
     var  btnLeft = $("<input type='button' id='btnRight' value='<<' class='ButtonStyle' />");
           // appending buttons to a td inside a html div 
        $('#tdDoE').append(btnLeft);
    $('#tdDoE').append(btnRht);
    // Left / Rht Scroll scroll     
                $("#btnLeft").click(function () { 
                var leftPos = $('.DivDataMain').scrollLeft();
                $(".DivDataMain").animate({scrollLeft: leftPos + 250}, 600);
                });   
                    $("#btnRight").click(function () { 

                var leftPos2 = $('.DivDataMain').scrollLeft();
                $(".DivDataMain").animate({scrollLeft: leftPos2 - 250}, 600);
                });   

    });


HTML Code :-
       <div style="width: 300px; overflow: hidden;" class="DivDataMain">
        <table>
            <tr>
                <td id="tdDoE">
                        Scroll Buttons will be appended after this text.
                </td>
            </tr>
        </table>
    </div>

Friday, August 3, 2012

Display table design ( with data types ) with SQL QUERY

Display table design with SQL QUERY 


Execute folowing in SQL Query window

sp_columns <table name>

OR

sp_help  <table name>



Thursday, July 19, 2012

Get selected check box through JavaScript


window.onload = function () {
        getChkItem();
    }
function getChkItem() {
var chk = "";
var arrChk = new Array('cbID_1','cb_2',cb_3,cb_4,cb_6);  // checkbox 1 ID & check 2
for(iCtr=0; iCtr < arrChk.length; iCtr++){
 var element = document.getElementById(arrChkRht[iCtrRht]);
 if (typeof(element) != 'undefined' && element != null) {  if(document.getElementById(arrChk[iCtr]).checked){
chk = chk  + arrChk[iCtr].split("_")[1] + "," ;            
                }
}
alert(chk.slice(0, -1)); }

Friday, June 29, 2012

disable JavaScript Errors in IE


<script type="text/javascript">
 
function noError(){return true;}
window.onerror = noError;
 
</script>

Thursday, June 28, 2012

Insert selected records (checkboxes) from asp gridView & perform CRUD operations


Scenario :- I have to perform CRUD operation for selected records ( check boxes) in a GridView  ID as described in the image.









No what we are doing  is to perform a for loop on datatgrid & get selected checkbox id in a string varibale separted by ','.After that we will create a DB function that will split the checkbox ID'd string in new row for each id.


It will make CRUD operation very easy


GridView in aspx:-





  <asp:DataGrid ID="grdList" DataKeyField="diagnosis_id" Runat="server" AutoGenerateColumns="False"
AllowPaging="False" PageSize="100" ShowHeader="true"  >
<Columns>
<asp:BoundColumn DataField="diagnosis_name" HeaderText="DIAGNOSIS" SortExpression="diagnosis_name asc">
<HeaderStyle Width="75%" HorizontalAlign="Center" ></HeaderStyle>
<ItemStyle CssClass="greylabelsmall"></ItemStyle>
</asp:BoundColumn>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>






VB function to get selected checkboxes in datagrid




 Private Sub GetCheckedBox()
        For Each item As DataGridItem In grdICDList.Items
            If CType(item.FindControl("chkICD"), CheckBox).Checked Then
                icdIds = icdIds + Convert.ToString( grdList .DataKeys.Item(item.ItemIndex)) + ","
            End If
        Next
        If icdIds.Length > 0 Then
            If icdIds.LastIndexOf(",") > 0 Then
                icdIds = icdIds.Substring(0, icdIds.Length - 1)
            End If
            'SaveICDs()
            InsertDiagnosis(icdIds)
        End If
    End Sub








Now create a db Function like this:-


CREATE  FUNCTION [dbo].[Split]      
(      
 @RowData varchar(8000),      
 @SplitOn nvarchar(5)      
)       
RETURNS @RtnValue table      
(      
 Id int identity(1,1),      
 Data nvarchar(100)      
)      
AS       
BEGIN      
 Declare @Cnt int      
 Set @Cnt = 1      
      
 While (Charindex(@SplitOn,@RowData)>0)      
 Begin      
  Insert Into @RtnValue (data)      
  Select      
   Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))      
      
  Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))      
  Set @Cnt = @Cnt + 1      
 End      
       
 Insert Into @RtnValue (data)      
 Select Data = ltrim(rtrim(@RowData))      
      
 Return      
END 








And Use it in your stored procedures like this :-





                INSERT INTO INSERTABC         
                        (CPTID,   
                         
                         ICDID,   
                         CREATED_USER,         
                         CREATED_DATE,         
                         ISDELETED)         
       SELECT @CPTID,LTRIM(RTRIM(DATA)), @CREATED_USER,  GETDATE(),0   FROM SPLIT(@ICDIDS,','






Example :--


  SELECT DATA  FROM SPLIT(@ICDIDS, ',' )
Data will give you select check boxes ID in new rows.
  
   

Wednesday, May 30, 2012

Display Image from Database in ASP.NET


Scenario - I have image names (eg:- abc.jpg) saved in a database & actual images lie in a folder in file system (~/ClientImages/).
Now I want to retrieve image from db & diplay it on webpage,in a div 

Solution :-

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="id" DataSourceID="SqlDataSource1">
    <Columns>          
   <asp:TemplateField>
  <ItemTemplate>
  <asp:Image ID="img12" runat="server" Width="600px" Height="400" ImageUrl='<%# Page.ResolveUrl(string.Format("~/ClientImages/{0}", Eval("image"))) %>' />

  </ItemTemplate>
  </asp:TemplateField>

    </Columns>
</asp:GridView>

## SqlDataSource ##
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:XXXXConnectionStringName %>" 
    SelectCommand="Stored_Procedure_Name" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>