Pages

Ads 468x60px

For New Update Use this Link http://dotnethubs.blogspot.in/ Offer for you

.

Wednesday, 28 August 2013

How To Create A JSON Web Service In ASP.NET

How To Create A JSON Web Service In ASP.NET
Categories : -  How to create Ajax enable wcf web service in asp.net

Introduction : - 

 .ASP.NET makes it easy to create web services but they usually return XML. Like many web developers I now prefer JSON. This article and sample code will show you how to get your web service to return data in the JSON format.

Description : -

  For fetch the data from MySQL database using web service in asp.net json format  step as shown below.

 Step :- 1 Create a new web site 
Step : -2 Write click on website and add new web service 
Step : -3 Write a code on WebService.cs file

as shown below



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using MySql.Data.MySqlClient;
using System.Data;
using System.Web.Script.Serialization;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

     [WebMethod(Description = "Gets All Records.")]

       [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

      public string GetAllRecords() {

          MySqlConnection objConnection = new MySqlConnection("server=localhost;User Id=root;database=databaseName;Pooling=false;Connect Timeout=10;Allow User Variables=True;");

          MySqlCommand objCommand = new MySqlCommand("SELECT * FROM info_tab  ORDER BY id", objConnection);

          DataSet objDataSet = new DataSet();

          MySqlDataAdapter objDataAdapter = new MySqlDataAdapter(objCommand);

           objDataAdapter.Fill(objDataSet, "reading");

           objConnection.Close();
             // Create a multidimensional jagged array
           string[][] JaggedArray = new string[objDataSet.Tables[0].Rows.Count][];

           int i = 0;

          foreach (DataRow rs in objDataSet.Tables[0].Rows)

          {

               JaggedArray[i] = new string[] { rs["user_id"].ToString(), rs["First_Name"].ToString(), rs["Last_Name"].ToString() };

               i = i + 1;

           }

             // Return JSON data

           JavaScriptSerializer js = new JavaScriptSerializer();

          string strJSON = js.Serialize(JaggedArray);

          return strJSON;

       }  

}
 
For Connect to my sql  use the Connector .MySql Connector Download Link is Click

Run your service and seen output like this


Click on  GetAlRecords




 Again Click on Invoke Button and output as shown below


Note : - In Connection String i am not use a password If you define a password at the time of installation of MySQL database then use password=y our password; in connection string

Friday, 23 August 2013

Creating Ajax Enabled WCF Service in asp.net

Creating Ajax Enabled WCF Service in asp.net
Categories :- Introduction of WCF service , Advantages and Disadvantages of WCf  Service , Difference betweenWCF service and asp.net service

Introduction :- 

In my previous article i have explain to create restful wcf service api using post step by step .and i have also explained another example for create basic  wcf service step by step in asp.net. In this article, I will explain how to create an AJAX-enabled WCF Service and how to consume it using client-side script in an ASP.NET page. I have kept the example quiet simple so in order to keep our focus on creating and consuming AJAX Enabled WCF Services.

Description :-

AJAX-enabled WCF Service is a service that can be consumed using an AJAX client-side script.
I am using visual stdio 2010 for create a ajax enable wcf service in asp.net.This is very easy for create wcf enable service in asp.net.Follow the step for create a ajax enable web service in asp.net as shown below

Step 1 :-  Open Visual Studio 2010.    Go to File->New->WebSite     Select ASP.NET Empty WebSite

Step 2 : - Go to Solution Explorer and right-click.

    Select Add->New Item ,  Select WebForm ,     Default.aspx page open

Step 3 : -Define WCF Service :
 Go to Solution Explorer and right-click.
    Select Add->New Item ,  Select AJAX Enabled WCF Service ,  Define the Namespace

Step 4 :- Open Default.aspx page and click in [Design option].

 Drag and drop Scriptmanager Control  on the default.aspx web form. Image of form as shown below



Step 6 : -In [design] page right-click in scriptmanager control
Select Properties option
Define Services like this

Click the add option and select Service path like this

you can check this service on click on soure default.aspx design page


<asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="ajax.svc" />
            </Services>
        </asp:ScriptManager>

Step7 : - You have already select AJAX Enabled WCF Service in your app_code folder .
select ajax.cs webservice and double click on code behind and write the following




  [ServiceContract(Namespace = "GreetNM")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ajax
{
    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
    // To create an operation that returns XML,
    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    //     and include the following line in the operation body:
    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    [OperationContract]
    public void DoWork()
    {
        // Add your operation implementation here
        return;
    }
    [OperationContract]
    public string GetUser(string user)
    {
        return "Hello="+user;
    }
  
}


Here  GetUser is  method called GreetUser(string uname) which takes a username and returns a string with the “Hello” greeting appended to the user name. Decorate the method with the ‘OperationContractAttribute’ to indicate that the method is a part of the contract.

step 8 :-
Now add a Html Button, an HTML Input box and <Div> to the Deafult.aspx page.After renaming the controls and adding the onClick event of the button, the markup will appear similar to the following and image as shown above as step number 6




  <div id="ajax_wcf" title="getuser">
  
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="ajax.svc" />
            </Services>
        </asp:ScriptManager>
    <input type="button" id="ajax_wcf" onclick="return ajx_wcf_call()" value="Submit" />
    <input type="text" id="txtnm" />
    </div>

Java Script code :

Step 7 : Now go to Default.aspx page and select Design option.

    Click in the input Button
    Define Java Script code for the on click event

Code :


<script language="javascript" type="text/javascript">
        function ajx_wcf_call() {
            try {
                var greeto = new GreetNM.ajax();
                greeto.GetUser($get("txtnm").value, OnGeetingComplet, OnError);

            } catch (Error) {
            alert("Error");
        }
        }
  
    function OnGeetingComplet(result)
    {
        $get("txtnm").value = result;
        alert(result);
    }

    function OnError(result) {
        alert(result.get_message());
    }
  
    </script>

Compete code as shown below


  <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function ajx_wcf_call() {
            try {
                var greeto = new GreetNM.ajax();
                greeto.GetUser($get("txtnm").value, OnGeetingComplet, OnError);

            } catch (Error) {
            alert("Error");
        }
        }
  
    function OnGeetingComplet(result)
    {
        $get("txtnm").value = result;
        alert(result);
    }

    function OnError(result) {
        alert(result.get_message());
    }
  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="ajax_wcf" title="getuser">
  
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="ajax.svc" />
            </Services>
        </asp:ScriptManager>
    <input type="button" id="ajax_wcf" onclick="return ajx_wcf_call()" value="Submit" />
    <input type="text" id="txtnm" />
    </div>
    </form>
</body>
</html>

The result as for enter the value in text box and click on button




Download sample code attached


Wednesday, 14 August 2013

Could not find file exception in asp.net fileupload

Categories : - Create and read XML file in asp.net  , Interview question and answer , Regular expression image validation , Regular expression text box validate for numeric value onlyCould not find file exception in asp.net fileupload

Introduction :-

In this article i am explain how to avoid error file cloud not find when upload any image in folder using asp.net web form .

Error As shown below


Friday, 9 August 2013

GridView Paging Not Displaying Data After Switching Page

GridView Paging Not Displaying Data After Switching Page
Categories : - The GridView 'GridView1' fired event PageIndexChanging which wasn't handled

Introduction : - 

In this article i am explaining how i can show GridView Paging Not Displaying Data After Switching Page. In my previous article i have explained Java script for gridview in edit mode , Gridview rowcommand object reference not set to an instance of object

Description : -

I am having a bit of trouble with Paging within a GridView grid I have set up. I have added the paging but whenever I click on the next page or the last page buttons, the page refreshes and displays blank
So Bind the  Gridview as show below




  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BingGridViewData();//Call bind gridview function
    }


Create a new asp.net web site and add new page . Darg and drop gridview on page . and write this function on code behind of asp.net web page  as shown  below



protected void BingGridViewData()
    {
        _objcon = DonetionConnectionDB.GetConnection();
        DataTable dt = new DataTable();
        string query = "SELECT * FROM causes_tab order by ID DESC";
        MySqlDataAdapter _objda = new MySqlDataAdapter(query, _objcon);
        _objda.SelectCommand.CommandType = CommandType.Text;
    
        _objda.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        _objcon.Close();
    }



The gridview 'gridview1' fired event pageindexchanging which wasn't handled. c#

The gridview 'gridview1' fired event pageindexchanging which wasn't handled. Solution
Categories :-  Java script validation for Grid View in edit mode , Javascript validation for Gridview footer textbox  , Gridview RowCommand object reference not set to an instance of an object , onclick checkbox select data from gridview asp.net

Introduction  :-

In my previous article I have explained Gridview rowcommand object reference not set to an instance of object.  Now  i have  face this problem when i change the gridview AllowPaging="True" PageSize="1" .The Error message as shown below








 Description : -

Now i have a solution for this problem .
Select the Gridviw and click on PageIndexChanging Event of the Gridview and write a one line code as shown below



protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BingGridViewData();// GridView Paging Not Displaying Data After Switching Page
    }

Fired this event on code behind of the page and error is solved

Saturday, 3 August 2013

Regular expression validator for image file extension

Regular expression image file extension

Introduction :- 
In this article i have explained how to validate image using Regular Expression Validator  in  asp.net  before upload in data base or image fonder.In my previous article  i have explained  Different Validation Control in asp.net Like this :- How to allow numeric values into textbox , How to upload multiple photo using asp.net , Asp.net Control With Example , Jquery form validation in asp.net , JavaScript validation for grid view footer textbox , JavaScript validation for grid view in edit mode

 Description :- 

 In this Post I have created a new  project and add use a Regular Expression Validator in asp.net as show below

step 1 -    Create a  new project .
Step 2 -   Write Click on project explorer and add a new form .
Step 3 -   Drag and drop a RegularExpressionValidator and file upload control on the page.
Step 4 -   Drap and drop a  button on the web  page for save the image on click button in the image folder.
Step 5-    Write Click and add new folder in your project.

Now set the property for validate the image using RegularExpressionValidator  as show below

Control to validate =FileUploade
Text = Invalid image icon
 ValidationExperssion  =^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$"

 Complete Code as show below


<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        <asp:FileUpload ID="File1" runat="server" />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload" />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="File1" ForeColor="Red"
            ValidationExpression="^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$">Invalide file !</asp:RegularExpressionValidator>
  
    </div>
    </form>
</body>
</html>


Output image as show below




Download sample code attached







Monday, 29 July 2013

Latest asp.net interview questions and answers for experienced

Latest asp.net interview questions and answers for experienced
Introduction : -

I  have Collection new asp.net interview question and answer for experience and fresher .This is very important asp.net interview question with answer.
Every interviewer firstly ask 

1 . Tell me about Your Self ?

Ans  Good morning sir/madam.This is Chitranjan Singh Rathore My educational qualification are: I have completed my 10th standard in 2002 from  Little flower school and also 12th standard in 2004. I have completed my graduation in 2007 from Holkar science college. I have completed my post graduation in 2010 from Medicaps Colloege indore .
For More Click Here

 
2 . What is asp.net ?

Ans  Dot Net is a Framework technology, that means which is integrated with multiple technologies like windows, web, web services, etc.It is Use to develop web based, windows based application.
For More Click Here

3. Difference Between Form authentication and windows authentication ?

For Get the answer- Form authentication and windows authentication

4 . What is authentication and authorization in asp.net ?

Answer . This is very important question .every technical interview round ask this question
               authentication and authorization in asp.net

5.  What is web form ,windows form and client server architecture ?

Ans  - This is very important and interesting question.Now we will talk about(web form and windows form)

Web from :-

1 ) As we know web from use browser presentation(asp.net form has no exception )
2 ) ASP.NET Form inherits Page class (contained in System.Web.UI namespace).
3 ) Web Forms to create Web-based applications that display in a Web browser.
 4 ) Webapplications run on webservers (usually IIS)

Windows From : -

1 ) Window form has own presentation .
2 ) A Form of Windows Forms inherits Form class (contained in System.Windows.Forms namespace).
3 ) Windows Forms to create rich applications that install and run locally on a machine.
4 ) Windows forms are used in desktop based applications which heavily rely on the GDI.

Friday, 26 July 2013

How to upload multiple photos using asp.net

How to upload multiple photos using asp.net
Introduction :- 

In my previous  article i have explain the Ajax-asyncfileupload-control-example in asp.net. Now in this article we will upload multiple image using single file upload control in asp.net.

Description :- 

In this Article we take on file upload control and on button on asp.net web from.This is very important article for upload multiple image in database and folder .now we upload the multiple images in a folder some  easy process

Step 1 - Create a asp.net web project and add new from like this
Open visual stdio go to File->new ->Project  and write the name of the project

Step 2 - Write click on solution explorer and add new item ->select new web form->write the name of form

step 3 -  Drag and drop the file upload control on the form
Step 4 - Drag and drop the  asp.net Button on the form
Step 5 - Drag and drop one label on the form for count how many image you have select
Step 6 - Write click on Project (Solution Explorer) and add new folder and give the name to the folder is image

Note -: Write multiple="true" for select multiple file or  image using file upload control of asp.net
Note - use this namespace    using System.IO;

Complete Source Code as shown below

<asp:FileUpload runat="server" ID="UploadImages" multiple="true"/>
    <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />
    <asp:Label ID="listofuploadedfiles" runat="server" />



double Click on asp.net button control or write click on from and select  View Code .Go to code Behind File and write a code for upload a images in folder.

Code as shown below


      HttpFileCollection fileCollection = Request.Files;
        for (int i = 0; i < fileCollection.Count; i++)
        {
        HttpPostedFile uploadfile = fileCollection[i];
        string fileName = Path.GetFileName(uploadfile.FileName);
        if (uploadfile.ContentLength > 0)
        {
        uploadfile.SaveAs(Server.MapPath("~/image/slider/") + fileName);
      
        listofuploadedfiles.Text += String.Format("{0}<br />",uploadfile.FileName);
    }
    }



Tuesday, 23 July 2013

How to allow only Numeric values into a textbox

How to allow only Numeric values into a textbox
Introduction :-

In my previous article i have explained how i can use validation control in asp.net.In this article I am explain how i can allow online integer values for text box using regular expression in asp.net.

Description : -
In my Previous article i have explained how to validated form using jquery in asp.net.And i have Provided Full Description with example for  each and every  control in asp.net. Name of Controls are

RequiredFieldValidation,RangeValidator,RegularExpressionValidator,CompareValidator,CustomValidator,
CustomValidator

In this article i have explain how to validate textbox using regular expression allow only integer values

Process :-
1 : - Create a new project in asp.net and add new from and drag and drop a text box and provide the id to the textbox.In this article the id of text box is txt_priority  .
2 : - Drag and drop the Regular Expression validator on the form and set the property as show below
ID =RegularExpressionValidator1
ControtoValidate= txt_priority   [this is textbox id]
ErrorMessage=Please enter numbers only
ForColor=Red
ValidationExpression=\d+

complete example as show below


<asp:RegularExpressionValidator id="RegularExpressionValidator1"
                   ControlToValidate="txt_priority"
                   ValidationExpression="\d+"
                   Display="Static"
                   EnableClientScript="true"
                   ErrorMessage="Please enter numbers only"
                   runat="server" ForeColor="Red"/>


Wednesday, 17 July 2013

How to call asp.net web service from android application

create simple drop down menu using jquery
Introduction : -

 In this  article i am explaining how to call the asp.net  asmx web service .This is very nice article for call the asmx web  service for android application.
Setp 1 ->  Open visual studio and create a new project like this

File->new->Project
And write the name of project and click ok

Step 2  -> Write click on project  add ->add new item
select  web service and click ok and write the code as shown below on our webservice.asmx



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

  

    [WebMethod]
    public int Add(int a, int b)
    {
        return a + b;
    }

  
  
}

Step 3 -> Run our web service and check the output is proper or not  like this
Click on Add


Enter Values  a=10 and b=10

Then Click on Invoke and output as shown below

 
Start Android Applcation : -

step 1 -> Doble Click on eclipse IDE and  in front of you appear the GUI .
step 2 -> select File->new->Android Application Project
and fill all the filed as show in image


step 3-> Click Next->Next->Next->Next->Finish
Step 4-> On Android Application is Created

Step4->Download the jar file
ksoap2-android-assembly-2.5.5-jar-with-dependencies.jar

Step 5 -> Copy and past in libs folder and write click->Build Path->Configration Build Path

Note - If libs  folder not avable in our project then create new folder name like libs and keep this jar file

step 6 -> Now Write Click on  Project Add->New->Class  [class name like CallSoap.java]

And Write the Code as Shown Below 


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class CallSoap {
    public final String SOAP_ACTION = "http://tempuri.org/Add";

    public  final String OPERATION_NAME = "Add";

    public  final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

    public  final String SOAP_ADDRESS = "http://179.45.33.245/webservice/WebService.asmx";
    public CallSoap()
    {
    }
    public String Call(int a,int b)
    {
        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
        PropertyInfo pi=new PropertyInfo();
        pi.setName("a");
        pi.setValue(a);
        pi.setType(Integer.class);
        request.addProperty(pi);
        pi=new PropertyInfo();
        pi.setName("b");
        pi.setValue(b);
        pi.setType(Integer.class);
        request.addProperty(pi);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);

        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        Object response=null;
        try
        {
            httpTransport.call(SOAP_ACTION, envelope);
            response = envelope.getResponse();
        }
        catch (Exception exception)
        {
            response=exception.toString();
        }
        return response.toString();
    }
}

step 7 -> open activity_main.xml and copy and past the code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="hello" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="230dp"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="232dp"
        android:layout_height="wrap_content" />
   
   
  
   

    <Button
        android:id="@+id/button1"
        android:layout_width="229dp"
        android:layout_height="wrap_content"
        android:text="submit" />

   

</LinearLayout>
 
Step 8 -> Open the MainActivity.java

And write the code as shown below

import android.R.string;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textDisplay;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy =
                new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        setContentView(R.layout.activity_main);
        Button b1=(Button)findViewById(R.id.button1);
        //textDisplay =(TextView)findViewById(R.id.text);
        //textDisplay.setText("heloo");
        final  AlertDialog ad=new AlertDialog.Builder(this).create();

        b1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                CallSoap cs=new CallSoap();
                //soapshowrecord showrec=new soapshowrecord();               
                try
                {
                    EditText ed1=(EditText)findViewById(R.id.editText1);
                    EditText ed2=(EditText)findViewById(R.id.editText2);
                    int a=Integer.parseInt(ed1.getText().toString());
                    int b=Integer.parseInt(ed2.getText().toString());
                    //EditText ed3=(EditText)findViewById(R.id.text);
                    //String record=(ed3.getText().toString());
                    ad.setTitle("OUTPUT OF ADD of "+a+" and "+b);
                   
                    //String resp1=showrec.Call1(record);
                    //record=resp1;
                   
                    String resp=cs.Call(a, b);
                    ad.setMessage(resp);
                }catch(Exception ex)
                {
                    ad.setTitle("Error!");
                    ad.setMessage(ex.toString());
                }
                ad.show(); }
        });
    }

}

Output as shown Below



Tuesday, 16 July 2013

Image slider in asp.net using jquery

create simple drop down menu using jquery
 Categories :- Image Slider In asp.net with example

Introduction : -

This is very easy  to implement the slider in  asp.net .In my previous article i have explained very nice example for implement the slider in asp.net.
This is very simple and easy to use  slider in our web page. in this post you can adjust the width and height as well as time delay of image

In this article you have to include a one .js file like this



<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>

Jquey Function is like this



<script type="text/javascript">
        $(document).ready(function () {

            var currentPosition = 0;
            var slideWidth = 600;
            var slides = $('.slide');
            var numberOfSlides = slides.length;
            var slideShowInterval;
            var speed = 2000;


            slideShowInterval = setInterval(changePosition, speed);

            slides.wrapAll('<div id="slidesHolder"></div>')

            slides.css({ 'float': 'left' });

            $('#slidesHolder').css('width', slideWidth * numberOfSlides);


            function changePosition() {
                if (currentPosition == numberOfSlides - 1) {
                    currentPosition = 0;
                } else {
                    currentPosition++;
                }
                moveSlide();
            }


            function moveSlide() {
                $('#slidesHolder')
                  .animate({ 'marginLeft': slideWidth * (-currentPosition) });
            }

        });

    </script>

Complete  Source As shown below

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
     <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
    <style type="text/css">
        #slideshow #slideshowWindow
        {
     
    width:512px;
    height:200px;
    margin:0;
    padding:0;
    position:relative;
    overflow:hidden;
        }

    #slideshow #slideshowWindow .slide {
    margin:0;
    padding:0;
    width:512px;
    height:384px;
    float:left;
    position:relative;
        }
   </style>

    <script type="text/javascript">
        $(document).ready(function () {

            var currentPosition = 0;
            var slideWidth = 600;
            var slides = $('.slide');
            var numberOfSlides = slides.length;
            var slideShowInterval;
            var speed = 2000;


            slideShowInterval = setInterval(changePosition, speed);

            slides.wrapAll('<div id="slidesHolder"></div>')

            slides.css({ 'float': 'left' });

            $('#slidesHolder').css('width', slideWidth * numberOfSlides);


            function changePosition() {
                if (currentPosition == numberOfSlides - 1) {
                    currentPosition = 0;
                } else {
                    currentPosition++;
                }
                moveSlide();
            }


            function moveSlide() {
                $('#slidesHolder')
                  .animate({ 'marginLeft': slideWidth * (-currentPosition) });
            }

        });

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div id="slideshow">
    <div id="slideshowWindow">
   
        <div class="slide">
            <img src="img/1.jpg" alt="http://dotnetnukes.blogspot.in"/>
        </div><!--/slide-->
       
        <div class="slide">
            <img src="img/2.jpg" alt="http://dotnetnukes.blogspot.in"/>
        </div><!--/slide-->
       
        <div class="slide">
            <img src="img/3.jpg" alt="http://dotnetnukes.blogspot.in"/>
        </div><!--/slide-->
       
        <div class="slide">
            <img src="img/4.jpg" alt="http://dotnetnukes.blogspot.in"/>
        </div>
       
    </div>
</div>
</center>
    </form> 
   
</body>
</html>




Download sample code attached






Image slider in asp net

Image slider in asp net
Introduction :- 
 In this Post i am explain how i can implement the slider in asp.net.This is very easy to implement the slider in asp.net.

Description : -

In my previous post i have explained  implement the drop down menu using jquery. Here i am explain implement the j query slider in asp.net .

In this Post first we  include the  .js and .css file in our page .Image as show below


Inculde .js and .css  on asp.net page as shown below



<head runat="server">
    <title>Slider in asp.net</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="Styles/coin-slider.js"></script>

    <link rel="stylesheet" href="Styles/coin-slider-styles.css" type="text/css" />

    <link rel="stylesheet" href="Styles/coin-slider-styles.css" type="text/css" />
</head>

In This  slider you can set the width and height of the slider image as shown below
You can control the speed and delay of image and set width and height according to you web page this script write in jqueryslider.js .Full Source Code You Can Download link are give below


$.fn.coinslider.defaults = {
        width: 700, // width of slider panel
        height: 200, // height of slider panel
        spw: 7, // squares per width
        sph: 5, // squares per height
        delay: 1000, // delay between images in ms
        sDelay: 30, // delay beetwen squares in ms
        opacity: 0.7, // opacity of title and navigation
        titleSpeed: 500, // speed of title appereance in ms
        effect: '', // random, swirl, rain, straight
        links : true, // show images as links
        hoverPause: true, // pause on hover
        prevText: 'prev',
        nextText: 'next',
        navigation: true, // show/hide prev, next and buttons
        showNavigationPrevNext: true,
        showNavigationButtons: true,
        navigationPrevNextAlwaysShown: false
    };

Complete code as shown below



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Slider in asp.net</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="Styles/coin-slider.js"></script>

    <link rel="stylesheet" href="Styles/coin-slider-styles.css" type="text/css" />

    <link rel="stylesheet" href="Styles/coin-slider-styles.css" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div id="games">
    <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/1.jpg" alt="http://dotnetnukes.blogspot.in" /></a>
     <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/2.jpg"alt="http://dotnetnukes.blogspot.in"  /></a>
      <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/3.jpg"  alt="http://dotnetnukes.blogspot.in" /></a>
       <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/4.jpg"  alt="http://dotnetnukes.blogspot.in" /></a>
        <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/5.jpg" alt="http://dotnetnukes.blogspot.in"  /></a>
         <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/6.jpg"  alt="http://dotnetnukes.blogspot.in" /></a>
         <a href=http://dotnetnukes.blogspot.in target="_blank"><img src="img/7.jpg"  alt="http://dotnetnukes.blogspot.in" /></a>
    </div>
    </center>
    </form>

    <script>
        $('#games').coinslider();
        </script>
</body>
</html>



Download sample code attached







Monday, 8 July 2013

Detecting mobile browsers in asp.net

Detecting mobile browsers in asp.net
 Introduction : -

 hello friend this is very good example for detect the mobile browser in asp.net .In this example you can restrict to user for use only mobile.And we also find the user agent of particular Mobile device.


We use the name space as shown below for regular expression


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using System.Text.RegularExpressions;//this is namespace for reg. exp.


 If we restrict our site for use in mobile then we use the following code as shown below


string u = Request.ServerVariables["HTTP_USER_AGENT"];
 Regex b = new Regex(@"(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex v = new Regex(@"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            if ((b.IsMatch(u) || v.IsMatch(u.Substring(0, 4))))
            {
            Response.Write("Browsermsg:" + "This is Mobile Browser");  
      //  Response.Redirect("http://dotnetnukes.blogspot.in//mobile");
        }
    
        else
        {
            Response.Write("Browsermsg:" + "This is not Mobile Browser");
          // Response.Redirect("http://dotnetnukes.blogspot.in//Wbsite");
        }




Download sample code attached

Saturday, 6 July 2013

How will you open a new page after certain interval of time

Open new page in java script after some time interval

Introduction :-
Open the new page after some time interval using asp.net

More Details :-
 In my previous article i have provide the java script remove duplicate values from array  and java script get user IP address.

In this article i have show how i can redirect to asp.net or any html page after some interval without click of any user.This type of  functionality e use in html5 game for show the instruction and after display the instruction page automatically redirect to game play screen.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="interval.aspx.cs" Inherits="interval" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Java scripts Interval and redirect to other page</title>


     <script type="text/javascript">
         var i = 0;
         function ShowCurrentTime() {
             var dt = new Date();
             document.getElementById("lblTime").innerHTML = 5 - i + " Seconds";
             i++;
             if (i == 5) {
                 setTimeout("location.href='http://dotnetnukes.blogspot.in'", 0);
             }
             window.setTimeout("ShowCurrentTime()", 1000); // 1000 equal to 1 sec
         }
</script>
</head>
<body onload="ShowCurrentTime()">
    <form id="form1" runat="server">
  
    <div>
    <label id="lblTime" style=" font-weight:bold; font-size:x-large"></label>
    </div>
    </form>
</body>
</html>


Download sample code attached







Wednesday, 3 July 2013

What is Globalization and Localization in .NET

Globalization and Localization in .NET

Globalization :-

1 ) A. Globalization is the concept of developing the application in more than one language while the Localization is used for a particular language. Like if we develop the application in more than one language we need to create the resource files (.resx) by using System.

 2) Globalization is the process of designing and developing applications that function for multiple cultures

 Localizations :-

1 )  when we open the application in a particular language, then the localizations used to convert that application to the selected language.

 2)localization is the process of customizing your application for a given culture and locale. The topics in this section describe how to create ASP.NET Web applications that can be adapted to different languages and cultures."


What are in-proc and out-proc? Where are data stored in these cases?

  In-Processs : -

1 ) A. In-Proc and Out-Proc is the types of Sessions where the session data can be stored in the process memory of the server and in the separate state server. When the session data is stored in the process memory of the server, the session is called as the In-Proc server. In this case when the server is restarted, the session data will be lost

2 ) So in the in-Proc session state, the session data is stored in the Process memory of the Server where the application is running.

Out Process : -

1 ) When the session data is stored in the separate server like in state server or in Sql Server, the type of session is called as the Out-Proc session. In this case, if the server where the application is running is restarted, the session will be still remain in the separate servers.

2 )In the Out-proc session state, the session data is stored in the separate server- may be state server or in sql server.

Friday, 28 June 2013

boxing and unboxing in c#

boxing and unboxing in c#
Boxing :-

  means converting value-type to reference-type.

Eg:

int I = 20;

string s = I.ToSting();

UnBoxing :- 
 means converting reference-type to value-type.

Eg:

int I = 20;

string s = I.ToString(); //Box the int

int J = Convert.ToInt32(s); //UnBox it back to an int.


Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.

Value Type :-
As name suggest Value Type stores “value” directly.
For eg: 


//I and J are both of type int
I = 20;
J = I;

int is a value type, which means that the above statements will results in two locations in memory.
For each instance of value type separate memory is allocated.Stored in a Stack.
It Provides Quick Access, because of value located on stack.
 Reference Type : -

As name suggest Reference Type stores “reference” to the value.
For eg: 


Vector X, Y; //Object is defined. (No memory is allocated.)
X = new Vector(); //Memory is allocated to Object. //(new is responsible for allocating memory.)
X.value = 40; //Initialising value field in a vector class.
Y = X; //Both X and Y points to same memory location. //No memory is created for Y.
Console.writeline(Y.value); //displays 40, as both points to same memory
Y.value = 60;
Console.writeline(X.value); //displays 60.
Note: If a variable is reference it is possible to indicate that it does not refer to any object by setting its value to null;

Reference type are stored on Heap.
It provides comparatively slower access, as value located on heap.

 

..




New Updates

Related Posts Plugin for WordPress, Blogger...

Related Result