1

I'm write this code for my page:

<script>
    function initialize() {
        var mapProp = {
            center: new google.maps.LatLng(51.508742, -0.120850),
            zoom: 7,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
    }

    function loadScript() {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://maps.googleapis.com/maps/api/js?key=&sensor=false&callback=initialize";
        document.body.appendChild(script);
    }

    window.onload = loadScript;
</script>

i want when asp button click the initialize function,and set the new value for this line:

center: new google.maps.LatLng(51.508742--->Load from asp:Text1, -0.120850--->Load from asp:Text2)

How can i do this?

1 Answer 1

1

you can call javascript functions from asp button events

private void Button_clicked(object s, EventArgs e)
{
    //your code...

    Page.ClientScript.RegisterStartupScript(this.GetType(), "calljs", "initialize();", true);

    // 'calljs' is just a key, can be anything
    // to pass values 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "calljs", "initialize(" + val1 + ", " + val2 + ");", true);
    // and modify your js function to allow parameters
}

or

if you want to call initialize(); before the button event fired,

add onclientclick="initialize();" attribute to asp button

Sign up to request clarification or add additional context in comments.

2 Comments

what is calljs? how can i send new value to function from asp textbox?
my friend i want when i fire the button send textbox value to javascript initialize() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.