function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById('directions_panel');
summaryPanel.innerHTML = '';
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment + '</b><br>';
summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
}
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
我的按钮事件未被触发...我想使用服务器端控件使用两个下拉列表控件显示获取路线,但我的按钮事件未被触发...我该怎么做?
<asp:Button ID="btnsubmit" runat="server" OnClientClick="return calcRoute();" Text="Submit" />
如何将javascript方法加入服务器端...请告诉我..
答案 0 :(得分:0)
为什么你首先得到一个服务器端按钮?
该按钮不会调用提交事件,也不会回发到服务器。那么为什么不简单地使用普通的html按钮?
即使您的Javascript函数也不会返回true或false,因此使用return calcRoute()
将始终返回false事件。
在任何情况下,请尝试使用普通的onClick事件而不是OnClientClick。
修改强>
在我看来,你在这里做的很多事情都可以使用jQuery以比你在这里尝试更好的方式解决。
答案 1 :(得分:0)
Syntax :
public void RegisterClientScriptBlock(
Type type,
string key,
string script,
bool addScriptTags
)
Parameters
type
Type: System.Type
The type of the client script to register.
key
Type: System.String
The key of the client script to register.
script
Type: System.String
The client script literal to register.
addScriptTags
Type: System.Boolean
A Boolean value indicating whether to add script tags.
public void Page_Load(Object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
String csname2 = "ButtonClickScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "alert('Hello World');";
cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type=\"text/javascript\"> function DoClick() {");
cstext2.Append("Form1.Message.value='Text from client script.'} </");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}
}
答案 2 :(得分:0)
我没有添加“返回”错误条件...我的Button现在正在收到PostBack,这可能是个问题。所以添加
返回false;
条件..
然后它会正常工作......感谢您的回复..