Monday, November 21, 2011

Get the Control ID in javasscript from Usercontrol or Data grid

use the given javascript to  get the control client id in javascript from user control or data grid

function GetClientId(strid)
{
     var count=document.forms[0].length;
     var i=0;
     var eleName;
     for (i=0; i < count; i++ )
     {
       eleName=document.forms[0].elements[i].id;
       pos=eleName.indexOf(strid);
       if(pos>=0)  break;           
     }
    return eleName;
 }

Javascript in usercontrol and custom control

In this article i will tell you how to add javascript in user control(Embedded source) and custom control
First if you have user control then you need to convert into custom control for this you read my article of this month DLL for user control.
if you have custom control open the Assembly.cs file

Step 1: Create javascript file and add into the solution
Step 2: please make sure your javascript should not have '<%= Control.ClientID %>' beacuse register start up script will not allow to find the control

Step 3: Use below javascript for finding the control in usercontrol or gridview

 function GetClientId(strid)
{
     var count=document.forms[0].length;
     var i=0;
     var eleName;
     for (i=0; i < count; i++ )
     {
       eleName=document.forms[0].elements[i].id;
       pos=eleName.indexOf(strid);
       if(pos>=0)  break;           
     }
    return eleName;
 }


Step 4: Change the build type to Embedded in your javascript file property.

Step 5:  In Assembly.cs file add line
[assembly:WebResource("Virtual_KeyBoard.VKScript.js", "text/javascript")], you need web.Ui package for this. In my case VKScript is the name of the javascript





Step 6:  Override the OnPreRender function in class file of solution  and add below lines

There are two different -2 technique to embedded the javascript

Technique 1:

ClientScriptManager cs = this.Page.ClientScript;
            using (StreamReader reader = new StreamReader(this.GetType().Assembly.GetManifestResourceStream(GetType(), "VKScript.js")))
            {
                string scriptCode = reader.ReadToEnd();
                cs.RegisterClientScriptBlock(this.GetType(),"Javascript", scriptCode, true);
            }

"This will show the script in page souce"

Techinique 2:
string resouce = "Virtual_KeyBoard.VKScript.js";
ClientScriptManager cs = this.Page.ClientScript;
cs.RegisterClientScriptResource(typeof(VirtualKeyBoard), resouce);

Webresouce.axd dynamically create script
example

<script src="/WebResource.axd?d=VGoSv7soghuqEqTXl_W8OcnRS_O6Sg_HFkP0Q7N6Kx3NtQ9dpBsCA7PnQRnxaS883X54KD66o8kcW6NDHr7vpRMHM5sNF6B2Fsn7tArccVnRO03aF55GsI6Dz12tfkiF3AW04g2&t=634574601134363084" type="text/javascript"> 
script>

Thanks for reading this article. if you like this article please comment on this article.



Sunday, November 20, 2011

Install XP From USB Drive

Installing the xp from the pen drive is very easy and faster then cd/dvd drive

Step 1: Make your pend drive bootable
for making your pen drive bootable download the below given zip file

http://www.mediafire.com/?twixh1iid8cltoh

Step 2: Insert the USB drive and  extract the downloaded zip file.

Step 3: Run HP USB Formatter exe file.

Step 4: Select the Option create dos start up disk

Step 5: Using file system located at option : select extracted folder




Step 6:  Click start and format the Usb drive

Step7: Copy all the files from the extracted folder to Usb drive.

Step 8: Copy all files from Xp cd to Pen drive.

Step 9: Boot your System and select change boot option menu ( there are several different keys for this ) del, f10, f9 , f11 depands upon the system.

Step 10: Select the usb drive for booting the type SYS d: and press enter key, system will show system transferred.

Step 11: Then type nc - Nortan commander copy all files from pendrive to c drive

Step 12: Then type cd i386 and press enter

Step 13: Then type winnt and press enter key Sytem will start installing xp normal as cd/dvd drive.





Saturday, November 19, 2011

Create DLL for User Control ( Redistribution )

In this article i will tell you how to create dll from the user control and use that dll in other web application in .net

Step1: Create a class library solution in visual studio.

Step 2: In references add the reference of System.Web dll

Step3: In class file add the namespaces
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Reflection;

Step 4: Add the User control but remove ascx.cs file and designer file and change ascx page control directive
<%@ Control Language="C#" AutoEventWireup="true" %>
In my case user control is ( "VKBoard.ascx" ). then go to the property of the user control and change build action to embedded resource

Step5: in class file override the oninit () function

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// loads markup from embedded resource
string content = String.Empty;
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "VKBoard.ascx");
using (StreamReader reader = new StreamReader(stream))
{
content = reader.ReadToEnd();
}
Control userControl = Page.ParseControl(content);
this.Controls.Add(userControl);

//Put content is my function for adding the text in the control or what you want to do with control add initialization time
PutContent();
}



Step 6: Compile the solution

Step 7: Go to the solution directory and then in bin folder you will get the debug or release folder.
take the dll from there

So now you have a dll

Step 8: Add the reference of the dll (in my case it is virtualkeyboardlib.dll)

Step 9: in aspx page ragister the control

<%@ Register Namespace="VirtualKeyBoardLib" Assembly="VirtualKeyBoardLib" TagPrefix="CC" %>

Step 10: Use the control in aspx page



for more knowledge i am posting the whole files code and image below:



Code for VirtualKeyBoardlib.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Reflection;

namespace VirtualKeyBoardLib
{
public class VirtualKeyBoardLib : UserControl
{
private List DataPosition = new List();
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// loads markup from embedded resource
string content = String.Empty;
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "VKBoard.ascx");
using (StreamReader reader = new StreamReader(stream))
{
content = reader.ReadToEnd();
}
Control userControl = Page.ParseControl(content);
this.Controls.Add(userControl);
PutContent();
}

private void PutContent()
{
Random randomnum = new Random();
for (int i = 0; i < 10; i++)
{

while (true)
{
int value = randomnum.Next(0, 10);
if (DataPosition.Contains(value))
continue;
else
{
DataPosition.Add(value);
string buttonid = "Button" + (value + 1);
Button btn = (Button)this.FindControl(buttonid);
btn.Text = i.ToString();
break;
}
}
}
}



}
}

VKBoard.ascx



Add dll in other project



Default.aspx


Output:



thanks for reading this article. If you really like this please comment on this article and give your valuable response.