Saturday, December 21, 2013

How To OverLap A Div On Another Div C#

In this tutorial I will show you how can you overlap a div on another div. This is usefull for dropdowns

For this 2 properties of css are important
  • z-index:1;
  • position:absolute;
z-index
 
The z-index is use to define which div will appear in front, it does this by assigning a number so for example a div with z-index:1 will overlap a div with z-index:0

position

The div which you want to overlap to another div should have a property of either position:absolute or position:Fixed

I hope it was informative for you and I would like to Thank you for reading.

Wednesday, December 18, 2013

Connect ASPNETDB withVisual Studio

While configuring Web Site Administration Tool if you have encounters the following errors than you are at the right place 
  • There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
  • The following message may help in diagnosing the problem: Unable to connect to SQL Server database.

Provider Management

Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.
 

Solving this issue is quite simple, just follow the simple steps

1. Fist run the utility aspnet_regsql.exe to create your ASPNETDB

Now in order to connect to this DB within your visual studio

2. Inside Visual studio open up your project web.config file

3. Add the following lines inside <configuration> tag 

<connectionStrings>

    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="data source=.;DataBase=aspnetdb; Integrated security=true;"/>


  </connectionStrings>


There are three things in this connection string
  • data source (If your database is present on the machine on which you are working than leave it as it is)
  • DataBase (If you have explicitly changed your DataBase name than change aspnetdb with your DataBase Name)
  • integrated security (If you are using windows authentication than leave it as it is)
4. Save and Built

That's it now start ASP.NET Configuration(WSAT) and it should work properly this time

I hope it was informative for you and I would like to Thank you for reading

Tuesday, December 17, 2013

HOW TO IMPORT AND EXPORT SCHEMA IN ORACLE

Hello,

In oracle you can import and export user's schema i.e. tables and fields. This is important in a situation when you have created the tables on your computer and now want to move them on another computer.

In this tutorial I will first show you how to export the schema of a particular user and than how to import that schema. I will export the schema of user scott, you can use other account as well.

1. Open up your cmd

2. Now type exp scott file=c:\exp_scott.dmp

  • scott is the name of user who's schema I just exported
  • You can change the path and file name according to your need
Now I will create a new account name "ali" and imp this schema in that account, CLICK HERE if you don't know how to create an account in Oracle.

Now in order to imp the schema

3. Type imp fromuser=scott touser=ali file=c:\exp_scott.dmp

 
  • Replace scott name with the user name, who's schema you are about to import
  • Replace ali with the user name, who is going to imp this schema
  • Replace the path and file name to where you have saved the schema while exporting
You have now successfully imported the schema.

If you have any further queries than please don't hesitate to comment.

Thanks

Monday, December 9, 2013

HOW TO CREATE USER IN MYSQL STEP by STEP

Hello,

In this tutorial I will show you how you can create a user account in mysql and assign permission to that account according to your need.

1. Open up your command prompt

2. Inside CMD navigate to bin folder inside your mysql and type mysql

Now mySql stores all the user information in a database called mysql, so we will use this database to create a account

3. Type use mysql ;

Now Inside this database there is a table name user, we will use this table. If you want to take a look of this table type select * from user \G ;


By using the above query you can see it list all the privileges you can set along with Host,User and Password

4. Now in order to create a user type the following query

insert into user (Host,User,Password,create_privs,delete_priv,update_priv,insert_priv) values ('localhost','Ali',Password("f00"),'Y','Y','Y','Y');

Now to describe the above query

As you can see I used 4 types of privileges and set them to yes, all the remaining privileges will set to No by default. You can specify fields according to your requirement.

Now for the password, I used a built in function name Password(), This function is use to decrypt our password, as you can see the below figure although our password is f00 but it is listed as a complex number

5. Last but not least, we have create the account but it is not active yet to make it active the following

 FLUSH PRIVILEGES;


This will change the update the privileges and you can use the newly created account.

If you have any further queries than please do comment.

Thanks 

Friday, December 6, 2013

How To Create a VPN Server Windows 7

To create a VPN Server just follow the steps

1. Goto Control Panel, and select network and sharing center


2. Now from the left menu, click on Change Adapter Settings


3. Now from file menu select New Incoming Connection (You must be a system administrator to perform this step)


4. Now from the newly opened window, select the users to whom you want to allow to access VPN Server (Your client will use these account to access the VPN), Click on Next
  • You can also add new user by clicking on Add someone button

 5. Now put checkmark on Through the Internet, Click on Next


6. Now select the protocol you want to use for the VPN Server. (It is recommended to leave all setting default)


7. Select Internet Protocol Version 4(TCP/IPv4), and click on properties

8. Select Specify IP Addresses 

9. Now enter the IP address range that your clients will use to access your internal network, click on OK


The IP network should match against your internal IP network

10. Now Finally click on Allow Access

If you want users to connect to this VPN Server through internet, than you would need to forward port 1723 to your IP Address

You can find more information about portforwarding on www.portforwarding.com
  • Your VPN Server is now ready for the clients to connect
  • Client can connect to your VPN by either using your computer Name or by using IP Address
I hope it was informative for you, and I would like to Thank you for reading

Port Forwarding On PTCL ZXDSL 831CII Modem

Port forwarding allows remote computers (for example, computers on the Internet) to connect to a specific computer or service within a private local-area network (LAN).

In this tutorial I will show you how to forward ports for Remote VPN.

In order to allow remote users to connect to VPN server a port 1723 must be forwarded.

This tutorial is specific for PTCL ZXDSL 831CII Modem, since different model/router have different option and GUI. But the concept will remain same

1. Open up your browser, and in the address bar type 192.168.1.1
  • You will be asked for User Id and Password just type admin for both options

2. Now from the top Menu click on Advance


3. From Left menu click on NAT


4. From the dropDown menu select PVC7
  • Afrer selecting click on Virtual Server


5. Rule Index : Total 16 rules for port forwarding can be added you can select any free index that is not being use by any other application

Application : Type a short description/name of application for which you are port forwarding

Start Port Number : Enter starting range for port to include in this rule

End Port Number : Enter the end range for port to include in this rule

Local IP Address : Type the IP Address of the PC for which your VPN server is installed

6. Finally Click on Save

You are done you have successfully forward yout ports for VPN server

I hope it was informative for you, and I would like to Thank you for reading.

How to Create A VPN Client Windows 7

To Create a VPN Client Follow the simple Steps

1. Goto Control Panel and select Network and Sharing Center

2. Now Select Set up a new connection or Network


3. Select connect to a workplace, and click on Next


4. Select Use my Internet Connection (VPN)


5. In internet Address type the IP or Domain name address of your VPN Server, click on Next
  • You can assign a unique name for this connection in Destination Name


6. Enter the username and password that will be use to connect to VPN Server. (VPN Server Administrator will provide you this information)


7. Now finally click on Connect


Thats it you will be connected to your VPN

I hope it was informative for you, and I would like to Thank you for reading.

Thursday, December 5, 2013

ORA-28000 - HOW TO UNLOCK ACCOUNT IN ORACLE

Hello,
   while connecting to oracle other than sysdba you might have encounter an error something like below

ORA-28000: the account is locked


this is because when we install oracle by default all accounts are locked except for sysdba and system account. Now in order to use the locked account, we will first have to unlock it.

ok so in order to unlock the account, you must be connected to oracle you can use either sysdba or system account which are by default unlocked.

1. In SQLPlus type conn / as sysdba, than hit enter now it will ask you for password by default the password is set to sysdba you can simply hit enter or you could type the password both are acceptable.

2. Now type alter user scott account unlock;

Now even though the account is unlocked, but we still cannot use it to connect to oracle, why because we will need to assign a password to this account.

3. type alter user scott identified by tiger;


We have successfully unlock the account "scott" and set it's password to "tiger"

If you have any further queries than please do comment.

Wednesday, November 27, 2013

Virtual Paths not working in Response.Redirect ASP.NET

Hello,

Usually when we use Response.Redirect() method to redirect to a webpage or folder this works fine if both webpage i.e. current and the requested one are on the same level/folder

Response.Redirect(/Account/webpage.aspx)

Response.Redirect(~)
the '~' sign means the application's root level

so now from application root level we can define the path

Additionally you can use Response.WriteFile() method

Wednesday, November 13, 2013

HOW TO INSTALL BOT IN CS PODBOT

Hello,
          In this tutorial I will show you how can you install and play with bots in your counter strike.
Thing you will need

Podbot (Download from HERE)
file is password protected, password is 'taqi'

1. After download Podbot extract it, there you will find 4 folders and a .gam file

2. Copy all 4 folders and the .gam file

3. Paste it in your cstrike folder
for me the path is c:\program files\valve\cstrike\

You will be warned about file replacing, just click on Yes to All

And you are done, you have successfully installed Bots in your counter strike

To check if PodBot is installed successfully

1. Run hlds

2. Make a server

3. Now go to console tab and type meta list , and you should find the line below


As you can see POD-Bot is installed

I hope this was informative for you, and I would like to thank you for reading

Friday, November 8, 2013

How To Find Physical Path In ASP.NET

Following are some properties through which we can find physical path of our ASP.NET Web Application

  • string path1 = HttpContext.Current.Request.PhysicalApplicationPath;
  • string path = Server.MapPath("/");
  • string path2 = Server.MapPath("~");
  • string path4 = AppDomain.CurrentDomain.BaseDirectory;
I Hope it was informative for you, and I would like to Thank You for reading

jQuery not firing in Content Page derived from Master Page

If Your jquery is not working in Content Page i.e. Web form using Master page than try the following

usually we get DOM by $("#ControlName")

The above method should work properly when the web form is not derived from Master Page

But when the page is derived from Master Page all controls id's are changed hence the above method will not find reference of the control

Now in order to find correct reference we should do something like this

 var reference = $("#<%=controlName.ClientID %>")

This way we can get the reference and assign it to a variable

Now using variable we can work on the control like we usually do it jquery

I hope it was informative for you, and I would like to Thank you for reading

Wednesday, November 6, 2013

How To Hide Certain Column in datagridview C#

In order to hide certain column of datagridview, do something like this

dataGridView1.Columns[4].Visible = false;
  • where dataGridView1 is the name of your datagridview
  • Column starts from index 0 
You can hide multiple columns just change the index number

I hope it was informative for you, and I would like to Thank you for reading

Tuesday, November 5, 2013

How To Pass Array to a Web Method or Web Service Method

In this tutorial I will show you how to pass an array to a Method this can also work for web service method as well.

1. First we need to define a array and it some data in it


   1:              string[] array = new string[20];
   2:              for (int i = 0; i < 4; i++)
   3:              {
   4:                  array[i] = "This is number " + i;
   5:              }
 
 
Here I have define an array of type string, this can be of other type as well.

2. Now we will create a method that will accept a array of type string as a parameter


   1:  public void compressFiles(string[] objlistt)
   2:          {
   3:                  for (int i = 0; i <objlistt.Length; i++)
   4:                  {
   5:                  // your code here
   6:                  }
   7:          }
 
3. Now to send the array to the method, you will need to call that method like this


   1:  compressFiles(array);
 
I hope it was informative for you, and I would like to thank you for reading

How To Fix Apache Server No Service Installed

Hello,

 If you have encounter an error while installing Apache Server like below, than you are at the right place, in this tutorial I will tell you why these error occur and what does these error means.



  • The First error window means that something is interfering with port 80 and it is not letting Apache Server to use this port.
In my case the problem was with the IIS, IIS was already installed on my machine now because it was using the port 80 that's why Apache gave error that it cannot bind the port 80.
  • The Second error window state that after installing Apache, the system could not find service called "Apache2"
In our case because it couldn't bind the port 80, so it didn't register the service

So what is the solution ?? you have 2 options.

1. Disable IIS service (Click to find How)

OR

2. Change your website port to something else in IIS (Click to find How)

If you have any further queries, than please do comment.

Thanks

Monday, November 4, 2013

How To Disable IIS Service

Hello,
          In this tutorial I will show you how to Disable IIS Service.

1. Click on Start Menu and than Click on Run

2. Type services.msc and click on OK

3. Now find service called IIS Admin Service, right click on the service and click on Stop



You will receive a warning message like above because

  • World Wide Web Publishing Service
  • Windows Remote Management (WS-Management)
  • HTTP SSL
All these 3 services are dependent on IIS, so if you stop IIS these services will be stop as well

4. Click on Yes

Keep in mind that, IIS will start again next time when you start your windows, to keep it disable for future you would need to right click on IIS Admin Service and click on properties, than from there change the start-up type to Disable.

That's it you have successfully disabled IIS.

If you have further queries please don't hesitate to comment.

Thanks

Wednesday, October 30, 2013

Oracle Error ORA-12560 solution

In oracle you might get an error while connecting

ORA-12561 : TNS: Protocol adapter error


This error usually come when the required oracle service is not installed or started

To fix this error just follow the following steps

1. Go to services by typing services.msc
(You must be a Administrator to perform this)

Now find service name "OracleServiceORCL"

2. Right click on this service and click on Properties

3. Now set startup type to Automatic

4. Below the service status label just click on Start Button

You are done now you can connect to SQLPLUS easily.

If you have any queries than please do comment

Thursday, October 24, 2013

How To Change Default Port Of Web Site in IIS

Hello folks,
                  In this tutorial I will show you how can you change the default port for your website i.e. port 80 to something else in IIS.

1. Open IIS by typing inetmgr in run command OR you can go to Administrative tools and Double click on IIS Manager

2. From Left panel expand Web Site folder

3. Right Click on your Web Site and Click on properties


4. In TCP port field type any port number that is not currently being used by any other application

5. Click on OK

That's it you have Successfully changed your web site port.

If you have any firther queries than please do comment.

Thanks

Friday, October 18, 2013

REPAIR WINDOWS 7 FROM USB DRIVE STEP BY STEP

Hello,
        You might got stuck in a situation where your windows 7 got corrupted and there is either no cd or cd rom to run recovery or reinstall windows.

Well in this tutorial I will show you how you can repair you windows 7 by using a USB drive

Before you continue, Make sure you fullfill the following requirements.

1. A USB 
2. System should support booting from USB
3. Windows 7 Repair Disk Download from HERE

 Ok So lets start

1.  Open up command prompt
(run it as an Administrator)

n    Now type the following commands

2. diskpart

3. listdisk

This will list down all the Drives connected to your system, Now you have to carefully select the USB drive which you want to use for windows recovery.
In My case the USB Drive is Disk 1, this could be different for you so choose carefully

4. Now type select disk 1

5. Clean

6. create primary partition

7. select partition 1 << again this is the partition number which you choose above

8. active

9. format fs=NTFS

Now Windows will start formatting your USB Drive, this might take some time depending on your drive size

10. Now type assign

11. type Exit



You have successfully format your USB drive, now it’s time to put the recovery files in this Drive
To do this

12.  Extract the Windows 7 Repair Disk files (which you downloaded above) in your USB Drive And you are done

If you have any queries than please do comment

Thanks

Wednesday, October 16, 2013

The type or namespace name 'OracleConnection' Could not be found C#

Hello,

In C# you you might have receive a type or namespace missing error like the one below
The type or namespace name 'OracleConnection' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'OracleCommand' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'OracleDataReader' could not be found (are you missing a using directive or an assembly reference?)     


This means that c# was unable to find the reference to for the following classes

               OracleConnection conn
               OracleCommand cmd
               OracleDataReader
All these classes are required to connect Oracle with c#

So in order to fix this error we will need to add dll(references) files for these classes.

Download dll from HERE
File is password protected, password is taqi

1. Download the dlls from link provided above

2. Now in C# right click on your project, and than click on Add reference

3. Click on Browse Tab

4. Now add the 3 files which you downloaded above

5. Click ok

Now Your code will compile without the namespace error

I hope it was informative for you and I would like to Thank you for reading.

Thanks

Saturday, October 12, 2013

Get GridView Column Value of Control C#

In order to find value of certain column of gridview, we need to find weather they are control or simple text

If they are control like Label, Hyperlink etc than we must use the findControl method to get the value

The following code will show you how to get value of a HyperLink type Column



   1:  foreach (GridViewRow gvRow in gv1.Rows)
   2:              {
   3:                  CheckBox chkItem = (CheckBox)gvRow.Cells[0].FindControl("GvCheckBox");
   4:                  if (chkItem.Checked)
   5:                  {
   6:                        HyperLink abc = (HyperLink)gv1.Rows[1].Cells[2].FindControl("hlFileName");
   7:                  }
   8:   
   9:                  else
  10:                  {
  11:                      //this code will execute if the CheckBox is Not Checked
  12:                  }
  13:              }
asdasdasd

Inside the (chkItem.Checked)

We first declare a variable abc of type HyperLink

Than using (HyperLink) we type cast the result which we will get

The Name of my GridView is gv1

To Change Rows just change the index or we can use variable as well

the FindControl() method which accepts 1 parameter we provide the Column Header and thus we are able to get the value of that column

I hope it was informative for you, And I would like to Thank you for reading.

Saturday, October 5, 2013

Find which CheckBox is Checked inside GridView C#

Below is a simple code that will help you finding all the CheckBox inside Grid View weather they are checked or Not Checked.

   1:  foreach (GridViewRow gvRow in gv1.Rows)
   2:              {
   3:                  CheckBox chkItem = (CheckBox)gvRow.Cells[0].FindControl("GvCheckBox");
   4:                  if (chkItem.Checked)
   5:                  {
   6:                     //this code will execute if the CheckBox is Checked
   7:                  }
   8:                  
   9:                  else
  10:                  {
  11:                      //this code will execute if the CheckBox is Not Checked
  12:                  }
  13:              }

We Define a variable called gvRow of type GridViewRow this will be use to hold information about each row

Now Because it is Control and it's type is CheckBox so we will need to typecast the result in CheckBox

I hope it was informative for you, and I would like to Thank You for reading

Tuesday, September 24, 2013

How To Validate TextBox using jQuery Block Unwanted Characters

Hello,
         In jQuery you might want to limit the user to type either only numbers or characters. We can do this with jQuery very easily.

1. First create a TextBox set it's id="TextBox1"



   1:  <body>
   2:      <form id="form1" runat="server">
   3:      <div>
   4:          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   5:      </div>
   6:      </form>
   7:  </body>

2. Now we will write jQuery to stop user from entering numbers 0-9, i.e. user is only allowed to type Alphabets and some special characters



   1:      <script type="text/jscript">
   2:          $(document).ready(function () {
   3:              $("#TextBox1").keypress(function (e) {
   4:                  if (e.key >= 0 && e.key <= 9)
   5:                      return false;
   6:              });
   7:          });
   8:      </script>

We limit the user from entering numbers using keypress event

I hope it was informative for you and I would like to Thank you for reading

Friday, September 20, 2013

How To Use HiddenField in ASP

The HiddenField in ASP.Net give us the facility to store our information in the page without displaying it. i.e. we can get and set the value of hiddenfield but they will not appear on the page.

We can use HiddenField property both in Server Side and Client Side

Note: You should not store sensitive data in HiddenField because even though it is hidden it can still be access able by viewing the page source.

In this post I will show you how to use HiddenField.

In this example I will first change the HiddenField value on client Side using jQuery and than at server side we will access that value



   1:  <html xmlns="http://www.w3.org/1999/xhtml">
   2:  <head runat="server">
   3:      <title></title>
   4:      <script type="text/jscript" src="jquery-1.9.1.js"></script>
   5:      <script type="text/jscript">
   6:          $(document).ready(function () {
   7:              $("#hf1").val("Value Changed from Client Side");
   8:          });
   9:      </script>
  10:  </head>
  11:  <body>
  12:      <form id="form1" runat="server">
  13:      <div>
  14:          <asp:Button ID="btn1" runat="server" Text="Click on me" OnClick="btn1_Click" />
  15:          <br />
  16:          <asp:Label ID="lbl1" runat="server"></asp:Label>
  17:          <asp:HiddenField ID="hf1" runat="server" />
  18:      </div>
  19:      </form>
  20:  </body>
  21:  </html>

In the source I define a textbox, a HiddenField, and a Label and than using jQuery I change the value of HiddenField

Now we will try to access this value from Server Side

   1:  protected void btn1_Click(object sender, EventArgs e)
   2:          {
   3:              lbl1.Text = hf1.Value;
   4:          }

When the User click on the button the value of hiddenField will be stored in our Label

I hope this was informative for you and I would like to Thank you for reading

Digital Clock in C#

I have developed this Digital Clock in C#

You will require Framework 4.0 for this to run on your Computer


Download the Digital Clock Application from HERE

Download the source code from HERE, for password please leave a comment.

Thanks

Monday, September 16, 2013

HOW TO CONFIGURE VIRTUAL PC AND INSTALL WINDOWS

Hello every1,

               Today in this tutorial I'm gonna show you how can you configure Virtual Machine to create a Virtual Hard Disk, and than How to install windows on it

Things you will need

1. Microsoft Virtual PC Download from HERE

2. Bootable ISO of Any Windows Setup

Ok lets GO!

1. Open Microsoft Virtual PC

2. Click on the New button
(A wizard will popup )

3. Click On Next

4. Select Create a Virtual Machine and click on Next

5.  Now assign a name to your Virtual Machine file, you can also choose a path to store your virtual Machine to specific location by click on Browse button

6. Click On Next

7. Now select the operating system from DropDown list, which you will install in Virtual Machine, if your OS name doesn't exist than select Other

8. Now you will configure amount of RAM for Virtual Machine, you can either select the default settings, or select Adjust The Ram Radio Button, and click on Next

8. Now select A New Virtual Hard Disk, and click on Next

9. Now select the path to store you Virtual hard disk(.vhd), You can also set the Virtual hard disk size.

10. Click on Next, than Finish.

You have successfully created your Virtual Hard disk, Now you can install windows on this Hard disk.

To install Windows on this hard disk

1.  Double Click on the newly created Virtual Machine


A window will open which will be similar to above one

2. From menu bar click on CD, and than click on Capture ISO image

3. Now select the .iso file of your windows setup

4. From menu bar click on Action and than click on Reset
This will restart you Virtual Machine, and it will boot using the ISO image that you just provided.

I hope it was informative for you and I would like to Thank you for reading.

Monday, September 9, 2013

Find Selected CheckBoxes in CheckBoxList C# ASP.Net

Find selected Checkboxes in a checkboxlist is quite easy using the foreach loop

1. First Create a checkboxlist and assign it's id="chklist"

2. Insert some random data inside your checkboxlist

3. Now using the following C# code you can find the selected checkboxlist


   1:   string a = "";
   2:              foreach (ListItem ls in chklisk.Items)
   3:              {
   4:                  if (ls.Selected)
   5:                  {
   6:                      a = a + ls.Text;
   7:                  }
   8:              }
The purpose of this foreach loop is to iterate through all the checkbox, if any checkbox is found selected than it's text will be stored in a sting called a

I hope it was informative for you, and I would like to thank you for reading

How To Publish Web Service in Visual Studio

Hello folks
                Today Im going to show you how to make a web service in Visual Studio C#

1. So first make a new project of ASP.NET Web Service Application

2. Name the project and click on OK

3. Now you will be redirected to Service1.asmx.cs page

4. In this page there is 1 method already created name as HelloWorld()

5. You can either use this method OR you can create your own method here

6. Now right click on the project and click on Publish


7. Select Web Deploy as Publish Method

8. Now in the Service URL type the address where you want to publish the Web Service for local computer you can simple type localhost, to publish on remote computer you will require administrative rights.

9. In Site/Application type Default Web Site/WebService2

* where webservice2 is the name of your web service

10. Finally click on Publish

You have successfully published you web service

To be able to access this service from any application you will also need to publish this on IIS, click HERE to see how to do this

Thanks

Saturday, September 7, 2013

Get TextBox value using jQuery

In this post I'm showing you how to get TextBox value and use them in jQuery

This method will work on both HTML control and ASP control

1. First we will define a TextBox assign it id="txt1"
<input type="text" id="txt1" /><br />
2. Now we will create a button, and assign it id="btnSubmit"
<input type="submit" value="Click" id="btnSubmit" />
3.Now we will write the required jQuery code so that when the user click on the button, we will get an alert of textbox Text
 


   1:  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"  
       type="text/jscript"></script>
   2:      <script type="text/jscript">
   3:          $(document).ready(function () {
   4:              $("#btnSubmit").click(function () {
   5:                  alert($("#txt1").val());
   6:              });
   7:          });
   8:      </script>

Following is the sample
Type A Text and Click on Submit button



Wednesday, September 4, 2013

How To Read XML Data through Ajax in jQuery


Hello,
         Today Im gonna show you how you can read data on XML file in jQuery via Ajax

I'm using Visual Studio 2010 as my text editor you can use any editor you like

1. Open up Visual Studio and create a new Empty Website project
2. Now right click on your project and add a XML file name it "XMLFile1.xml"
3. Now inside your XML file paste the following code & save it
<?xml version="1.0" encoding="utf-8" ?>
<data>

  <id>100</id>
  <name>Muhammad Taqi</name>
  <designation>Student</designation>

  <id>110</id>
  <name>Ali Raza</name>
  <designation>Software Engineer</designation>

  <id>786</id>
  <name>Muhammad Sagheer</name>
  <designation>Electrical Engineer</designation>
</data>
Now we will have to create a new web page in which we will call XML data using via Ajax using jQuery

5. Now right click on your project and add a New Web Page, name it whatever you want

6. Now just after the closing braces of <title> paste the following code


   1:  <script type="text/jscript" src="Scripts/jquery-1.9.1.js"></script>
   2:      <script type="text/jscript">
   3:          $(document).ready(function () {
   4:              $.ajax({
   5:                  url: "xmlfile1.xml",
   6:   
   7:                  dataType: "XML",
   8:   
   9:                  type: "GET",
  10:   
  11:                  success: FnSuccess,
  12:   
  13:                  error: FnError,
  14:   
  15:                  complete: FnComplete
  16:   
  17:              })
  18:          });  // .load closing
  19:   
  20:          function FnSuccess(result) {
  21:              var id = result.getElementsByTagName("id")[0];
  22:              var name = result.getElementsByTagName("name")[0];
  23:              var designation = result.getElementsByTagName("designation")[0];
  24:          }
  25:   
  26:          function FnError(result) {
  27:              alert("Error " + result.statusText);
  28:          }
  29:   
  30:          function FnComplete(result) {
  31:              alert("Operation has been completed " + result.status);
  32:          }
  33:      </script>
 
As you can see inside .Ajax method we have passed few parameters

URL This will be the url of your XML file

dataType We define what type of data do we expect in our case the returned data will of XML, if it's simple text we would have write text

type Here we can to define what method we are using either GET or POST

success Here we define a function called FnSuccess, this means if everything goes well than move to this function

error Here we define a function called FnError, this means if something goes wrong than move to this method

complete Here we define doesn't matter if operation is successful or not, when the request is completed than move to this method

You can download the completed project from HERE

I hope this was informative for you and I would like to thank you for reading