Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:48:23+00:00 2026-06-11T03:48:23+00:00

I have an Asp server control button for which I have onClick for processing

  • 0

I have an Asp server control button for which I have onClick for processing code in code behind and onClientClick to process javascript code. The codes are:

Update: As per Icarus solution, updated codes :

Button source:

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        style="z-index: 1; left: 648px; top: 202px; position: absolute" 
        Text="Show route" OnClientClick="droute(); return false" />

<asp:HiddenField ID="hdncroute" runat="server" /> 

Code behind:

protected void Button1_Click(object sender, EventArgs e)
{
    using (con = new MySqlConnection("server=localhost; uid=root;password=as64ws;database=Gmaps"))
    da = new MySqlDataAdapter("select * from routes where uid='" + Session["uname"].ToString() + "'", con);
    da.Fill(ds, "mroute");
    foreach (DataRow r in ds.Tables[0].Rows)
    {
        uroute.Add(r["latlng"].ToString());
    }
    croute = new string[uroute.Count];
    croute = uroute.ToArray();
    hdncroute.Value = string.Join("&", croute);
}

Javascript function:

function droute()
{
    var route=[];
    var temp;
    temp = eval(document.getElementById('<%= hdncroute.ClientID %>').value);
    route= temp.split('&');
    //Polyline icon n line settings
    var iconsetngs= {path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW, fillColor:'#FF0000'};
    var polylineoptns= {strokeColor:'#3333FF',strokeOpacity:0.8,strokeWeight:3,map:map,icons:[{icon:iconsetngs,offset:'100%'}]};
    polyline= new google.maps.Polyline(polylineoptns);

    //Loop to add locations and draw line
    var path= polyline.getPath();
    for(var i=0;i<route.length;i++)
        {
            var marker= new google.maps.Marker({position:route[i],map:map});
            path.push(route[i]);
            google.maps.event.addListener(marker,'click',showiwindow);
        }

    //Event Listener's
    function showiwindow(event)
    {
    iwindow.setContent("<b>Coordinates are:</b><br/>Latitude:"+event.latLng.lat()+"<br/>Longitude:"+event.latLng.lng());
    iwindow.open(map,this);
    }  
}

I know that writing return false for javascript function will avoid refresh, and also onClick has void return type. But still my page reloads on button click.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:48:24+00:00Added an answer on June 11, 2026 at 3:48 am

    You have an error here:

    route = document.getElementById('<%= croute %>').value;
    

    It should be:

    route = document.getElementById('<%= croute.ClientID %>').value;
    

    Update:

    Markup – declare a hidden element in the page

    <asp:hiddenfield id="hdnCroute" runat="server" />
    
    //code behind
    
    int [] croute = ... 
    
    hdnCroute.Value = "["+string.Join(",",croute)+"]";
    

    Now Javascipt:

    //now you have an array back in javascript 
    var route= eval(document.getElementById('<%= hdnCroute.ClientID %>').value); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASP.Net, I have a server control for which i would like to add
I have an ASP.NET MVC server app and client code which uses jquery. I'd
I have a disabled asp.Button, which I enable later with JavaScript. Like this <asp:Button
I have an asp.net server control (with the asp: in its definition). The button
I have the following control: <asp:TextBox ID=textbox1 runat=server Width=95px MaxLength=6 /> which i would
I have a custom asp.net server control to display images.What I need now is
I have the following textbox server control in my web page: <asp:TextBox ID=txtZip runat=server
I have a asp image control. ImageUrl=images/avator.jpg. I'm changing this picture on the server
I have a button on my ASP.NET page, which fetches some data from my
Greetings all, I have a simple JQuery function which is bound to an ASP:Button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.