我已经创建了一个新的Web应用程序,并删除了所有服务器控件。然后我从这个页面实现了谷歌地图和搜索框: https://developers.google.com/maps/documentation/javascript/examples/places-searchbox
实际上只是复制粘贴代码。
一切正常,就像在Google示例中一样,但问题是,当我搜索并按Enter时,页面会回发并因此重新加载页面为新..我无法找到触发重新加载页面的内容。< / p>
的Site.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Vegindex.SiteMaster" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link type="text/css" href="Styles/Site.css" rel="stylesheet" />
rel="stylesheet">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/JavaScript/map.js" />
</Scripts>
</asp:ScriptManager>
<div class="page">
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</div>
</form>
</body>
</html>
Site.Master.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Vegindex
{
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Default.aspx的:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="Vegindex._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div id="map" class="map"></div>
<input id="pac-input" class="controls" type="text" placeholder="Search Box">
<script type="text/javascript">
initialize(); // here is the Google code
</script>
</asp:Content>
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Vegindex
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:1)
要覆盖默认行为,您需要指定默认按钮。
在您的母版页中修改您的表单标记,如下所示:
<form runat="server" defaultbutton="btnDisableEnter">
并将相应按钮添加到母版页的底部:
<asp:Button ID="btnDisableEnter" runat="server" Text="" OnClientClick="return false;" style="display:none;" />
<强>声明:强>
采用的解决方案答案 1 :(得分:0)
您可以添加此按钮
<asp:Button ID="btnStopEnter" runat="server" style="display:none" OnClientClick="javascript:return StopEnter();" />
在java脚本中
function StopEnter(){
return false;
}
在C#中,您可以设置默认按钮
protected void Page_Load(object sender, EventArgs e)
{
Form.DefaultButton = btnStopEnter.UniqueID;
}