Faraz Shah's profileFaraz Shah Khan's spacePhotosBlogListsMore Tools Help

Faraz Shah Khan

Occupation
Location
Interests
Quite Difficult to know about me.... ya quite difficult.

Faraz Shah Khan's space

Code and Javascript to check/uncheck check boxes within GridView

Here is the code and the javascritp that can be used to check and uncheck the check boxes withing a GridView

///Code for GridView's ItemDataBound Event
if (e.Row.RowType == DataControlRowType.Header)
            {
                CheckBox chkNewAll = (CheckBox) e.Row.FindControl(Constants.RoleAccess_Grid_chkNewAll);
                chkNewAll.Attributes.Add(Constants.JavaScript_OnClick, "SelectDeSelectAll(this,'chkNew')");
}

/////Java Script//////
function SelectDeSelectAll(spanChk,elementid)
{
    //var elementid = 'chkNew';
 var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
    var xState = theBox.checked;   
 
    elm = theBox.form.elements;
       
        for(i = 0; i < elm.length; i++)
   if(elm[i].type == "checkbox" && elm[i].id != theBox.id )
   {
       var str = new String(elm[i].id);      
       if (str.indexOf(elementid, 0) > 0)
       {
        if(elm[i].checked != xState)
        {
            //elm[i].click();
            elm[i].checked = xState;
        }
    }
   }
}
function SelectDeSelectSpecific(spanChk,elementid,gridelement)
{
    //var Box = 'chkNew';
 var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
    var xState = theBox.checked;   
 var state = true;
    elm = theBox.form.elements;
       
        for(i = 0; i < elm.length; i++)
   if(elm[i].type == "checkbox" && elm[i].id != theBox.id )
   {
       var strall = new String(elm[i].id);      
       if (strall.indexOf(elementid, 0) > 0)
       {
           for(z = 0; z < elm.length; z++)
           {
               if(elm[z].type == "checkbox")
          
               {
                   var str = new String(elm[z].id); 
                       
                   if (str.indexOf(gridelement, 0) > 0 && str.indexOf(elementid, 0) < 0)
                   {
                    
                    if(elm[z].checked != true)
                    {
                   
                        state =false;
                    }
                }
            } 
        }
       
       
             elm[i].checked = state;
       
    }
   }
}

Getting HTML contents of the page

The code will give the HTML contents of the page rendered by the server
 
    protected override void Render(HtmlTextWriter writer)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        HtmlTextWriter htmlTW = new HtmlTextWriter(sw);
        //let regular rendering occur but capture the output
        //this will capture the full page markup
        base.Render(htmlTW);
       
        String markup = sb.ToString();
              
        //do whatever you need with the captured markup
        //such as assigning it to the body property of an email message
        // ...
        // ...
      
        //lastly give that markup back to the original writer
        //so that the page will still render
        writer.Write(markup);
    }  

JavaScript to access windows notepad of client's machine

If we want to access windows notepad or any other application from the browser of the client's machine use this javascript
 

<script>

 function go() {

   w = new ActiveXObject("WScript.Shell");

   w.run('notepad.exe');

   return true;

   }

  

 </script>

 -----------------------------

 <form>

   Run Notepad (Window with explorer only)

     <input type="button" value="Go"

     onClick="return go()">

</FORM>  

JavaScript to check/uncheck CheckBox control

Code which we can use to check/uncheck all the CheckBoxes with one check box mentioning Select All using JavaScript

<script Language="JavaScript">

function checkSelection()
{
    var frm = document.forms[0];
    var count=0;
    var controlCount=0;
    var firstControl=0;
    for (j=0;j<frm.elements.length;j++)
    {
        if (frm.elements[j].type=="checkbox")
        {   
            controlCount++;
            if (firstControl==0)
                firstControl=j;
        }
    }
    controlCount=firstControl+controlCount-1;

    for(i=firstControl+1;i<=controlCount;i++)
   
{   
        if (frm.elements[i].checked==true)
        count++;
    }

    if (count==controlCount-firstControl)
        document.getElementById("ctl00_ContentPlaceHolder1_CtrlDataExport1_chkSelectAll").checked=true;
    else
        document.getElementById("ctl00_ContentPlaceHolder1_CtrlDataExport1_chkSelectAll").checked=false;

}

</script>

Uploading File using FtpWebRequest

Here is the code that can be use to upload file using FtpWebRequest
 
FtpWebRequest ftpRequest;
FtpWebResponse ftpResponse;
    
try
{
 this.ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://ServerIP/FileName"));
 this.ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
 this.ftpRequest.Proxy = null;
 this.ftpRequest.UseBinary = true;
 this.ftpRequest.Credentials = new NetworkCredential("UserName", "Password");
 FileInfo ff = new FileInfo("File Local Path With File Name");//e.g.: c:\\Test.txt
 byte[] fileContents = new byte[ff.Length];
 using (FileStream fr = ff.OpenRead())
 { 
  fr.Read(fileContents, 0, Convert.ToInt32(ff.Length));
 }
 using (Stream writer = ftpRequest.GetRequestStream())
 {
  writer.Write(fileContents, 0, fileContents.Length);
 }
 this.ftpResponse = (FtpWebResponse)this.ftpRequest.GetResponse();
 this.Message = this.ftpResponse.StatusDescription;
}
catch (WebException webex)
{
 this.Message = webex.ToString();
}
December 22

Dell Inspiron 6400

Finally i bought my first laptop after waiting it for a long time on 9th Dec 2006 with following configuration
 
Dell Inspiron 6400
Intel Duo 2 Core 1.66 Ghz
1 GB DDR
120 GB Hard Drive
128 MB ATI Graphic Card
DVD +/-
15.4'' TFT Wide Screen
 
Of course I am extremly excited.
 
Photo 1 of 3

Quote of the Day

Loading...