Monday, February 27

Call jquery functions from Code behind in Asp.net

Here is my Source Code:

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


<!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></title>
    <script src="scripts/jquery-1.2.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
      
    </script>


     <script type="text/javascript">
    jQuery(window).ready(function(){  
             jQuery("#<%= Button1.ClientID %>").click(initiate_geolocation);  
         });  
   
         function initiate_geolocation() {  
             navigator.geolocation.getCurrentPosition(handle_geolocation_query);  
         }  
   
        function handle_geolocation_query(position){  
        enableHighAccuracy: true
             alert('Lat: ' + position.coords.latitude + ' ' +  
                   'Lon: ' + position.coords.longitude);  
                               
         }  
     </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

Here is my code behind:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SereversideJqueryExample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "InitiateGeoLocationScript", "<script type=\"text/JavaScript\" language=\"javascript\">initiate_geolocation();</script>");
    }
}

Thanks shibashish mohanty

4 comments:

  1. thank i need source Code
    it not play

    ReplyDelete
    Replies
    1. Can you show me your code.yes please check that you have the jquery plugin or not?

      Delete

Please don't spam, spam comments is not allowed here.

ShibashishMnty
shibashish mohanty