Click here to Skip to main content
14,870,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone, I hope you can help me with my problem. I am executing a SQL query inside ASP.NET code and I am using bing's javascript API. Problem is that I need to do a javascript function before running a query. This function provides geocoordinates based on the address in a string format. I already know for RegisterStartupScript and RegisterClientScriptBlock, but these two don't work for me because javascript is not executing for some reason. Here is the code. And, I almost forgot, the script is declared properly at the head of the page.

public void calculateCoordinates()
            ClientScriptManager cs = Page.ClientScript;
            Type cstype = this.GetType();
            String csName = "Calculate";
            if (!cs.IsStartupScriptRegistered(cstype, csName))
                String jsFunction = "calculateGeoCoordinates();";
                cs.RegisterStartupScript(cstype, csName, jsFunction, true);
Updated 3-Apr-13 16:34pm
[no name] 3-Apr-13 22:45pm
From the documentation, "The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised."
Parthanaux 3-Apr-13 22:50pm
But I need it to be executed even before that... Because I can't complete my query.
Karthik Harve 4-Apr-13 0:58am
did you tried with RegisterClientScriptBlock instead of RegisterStartUpScript ?

using AjaxControlToolkit;

Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Write your javascript code here');", true);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900