这个是ajax服务器控件的代码 GoogleMap.cs using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml.Linq;namespace MapControl { /// <summary> /// ServerControl1 的摘要说明 /// </summary> public class GoogleMap : WebControl,IScriptControl { private int _Zoom = 8; /// <summary> /// Gets or sets a value representing the zoom of the map. /// </summary> public int Zoom { get { return this._Zoom; } set { this._Zoom = value; } } /// <summary> /// Gets or sets the latitude value of the initial center point on the map. /// </summary> public double CenterLatitude { get; set; } /// <summary> /// Gets or sets the longitude value of the initial center point on the map. /// </summary> public double CenterLongitude { get; set; } private ScriptManager sm; public GoogleMap() { // // TODO: 在此处添加构造函数逻辑 // } protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Div; } } protected override void OnPreRender(EventArgs e) { if (!this.DesignMode) { // Test for ScriptManager and register if it exists sm = ScriptManager.GetCurrent(Page); if (sm == null) throw new HttpException("A ScriptManager control must exist on the current page."); sm.RegisterScriptControl(this); } base.OnPreRender(e); } protected override void Render(HtmlTextWriter writer) { if (!this.DesignMode) sm.RegisterScriptDescriptors(this); base.Render(writer); } public IEnumerable<ScriptDescriptor> GetScriptDescriptors() { ScriptControlDescriptor descriptor = new ScriptControlDescriptor("MapControl.GoogleMap", this.ClientID); descriptor.AddProperty("zoom", this.Zoom); descriptor.AddProperty("centerLatitude", this.CenterLatitude); descriptor.AddProperty("centerLongitude", this.CenterLongitude); yield return descriptor; } // 生成脚本引用 public IEnumerable<ScriptReference> GetScriptReferences() { yield return new ScriptReference("MapControl.GoogleMap.js", this.GetType().Assembly.FullName); } } } 这个是GoogleMap.js /// <reference name="MicrosoftAjax.js"/> Type.registerNamespace("MapControl");MapControl.GoogleMap = function (element) { MapControl.GoogleMap.initializeBase(this, [element]); this._zoom = null; this._centerLatitude = null; this._centerLongitude = null; // this._ers = null; this._mapObj = null; }MapControl.GoogleMap.prototype = { initialize: function () { MapControl.GoogleMap.callBaseMethod(this, 'initialize'); // 在此处添加自定义初始化 this.createMap(); }, dispose: function () { //在此处添加自定义释放操作 MapControl.GoogleMap.callBaseMethod(this, 'dispose'); }, get_zoom: function () { return this._zoom; }, set_zoom: function (value) { if (this._zoom !== value) { this._zoom = value; this.raisePropertyChanged("zoom"); } }, get_centerLatitude: function () { return this._centerLatitude; }, set_centerLatitude: function (value) { if (this._centerLatitude !== value) { this._centerLatitude = value; this.raisePropertyChanged("centerLatitude"); } }, get_centerLongitude: function () { return this._centerLongitude; }, set_centerLongitude: function (value) { if (this._centerLongitude !== value) { this._centerLongitude = value; this.raisePropertyChanged("centerLongitude"); } }, createMap: function () { // Set the center point, zoom, and type of map var centerPoint = new google.maps.LatLng(this.get_centerLatitude(), this.get_centerLongitude()); var options = { zoom: this.get_zoom(), center: centerPoint, mapTypeId: google.maps.MapTypeId.ROADMAP }; // Create the map, using the above options this._mapObj = new google.maps.Map(this._element, options); } } MapControl.GoogleMap.registerClass('MapControl.GoogleMap', Sys.UI.Control); if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();这个是ASP.NET网站Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MapControlTest._Default" %><%@ Register Namespace="MapControl" TagPrefix="mc" Assembly="MapControl" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager runat="server" ID="ScriptManager1"> </asp:ScriptManager> <div> <mc:GoogleMap ID="GoogleMap1" runat="server" CenterLatitude="36.1658" CenterLongitude="-86.7844" Width="500" Height="500"> </mc:GoogleMap> </div> </form> </body> </html>就是这三部分代码
<add assembly="MapControl, Version=1.0.4947.20127, Culture=neutral, PublicKeyToken=null"/>
这样吗? 加入之后还是没有用...
是不是命名空间的问题...
你好,还是继续问下你
这样算是引用了么?
可是还是出现问题
程序集“MapControl, Version=1.0.4947.31539, Culture=neutral, PublicKeyToken=null”不包含名称为“MapControl.GoogleMap.js”的 Web 资源。
这是数字变了
还有就是我对比了正确的例子 发现webconfig不一样
这是我的webconfig
这个是可以运行的成功例子的webconfig
加断点的话 我都不知道该加到哪
调试和编译的时候都报这样的错误
还有就是我对比了正确的例子 发现webconfig不一样
这是我的webconfig
这个是可以运行的成功例子的webconfig
加断点的话 我都不知道该加到哪
但是我自己写的例子的webconfig多出了好多 这问题到底出在哪..
<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表可以在
machine.config.comments 中找到,该文件通常位于
\Windows\Microsoft.Net\Framework\vx.x\Config 中
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 可将调试符号插入到
已编译的页面。由于这会
影响性能,因此请仅在开发过程中将此值
设置为 true。
-->
<compilation debug="false">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
通过 <authentication> 节可以配置
安全身份验证模式,ASP.NET
使用该模式来识别来访用户身份。
-->
<authentication mode="Windows"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节
可以配置相应的处理步骤。具体而言,
开发人员通过该节可配置要显示的 html 错误页,
以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
system.webServer 节是在 Internet Information Services 7.0 下运行 ASP.NET AJAX
所必需的。对早期版本的 IIS 来说则不需要此节。
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
GoogleMap.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;namespace MapControl
{
/// <summary>
/// ServerControl1 的摘要说明
/// </summary>
public class GoogleMap : WebControl,IScriptControl
{
private int _Zoom = 8;
/// <summary>
/// Gets or sets a value representing the zoom of the map.
/// </summary>
public int Zoom
{
get { return this._Zoom; }
set { this._Zoom = value; }
} /// <summary>
/// Gets or sets the latitude value of the initial center point on the map.
/// </summary>
public double CenterLatitude { get; set; } /// <summary>
/// Gets or sets the longitude value of the initial center point on the map.
/// </summary>
public double CenterLongitude { get; set; } private ScriptManager sm; public GoogleMap()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Div;
}
} protected override void OnPreRender(EventArgs e)
{
if (!this.DesignMode)
{
// Test for ScriptManager and register if it exists
sm = ScriptManager.GetCurrent(Page); if (sm == null)
throw new HttpException("A ScriptManager control must exist on the current page."); sm.RegisterScriptControl(this);
} base.OnPreRender(e);
} protected override void Render(HtmlTextWriter writer)
{
if (!this.DesignMode)
sm.RegisterScriptDescriptors(this); base.Render(writer);
} public IEnumerable<ScriptDescriptor> GetScriptDescriptors()
{
ScriptControlDescriptor descriptor = new ScriptControlDescriptor("MapControl.GoogleMap", this.ClientID);
descriptor.AddProperty("zoom", this.Zoom);
descriptor.AddProperty("centerLatitude", this.CenterLatitude);
descriptor.AddProperty("centerLongitude", this.CenterLongitude);
yield return descriptor;
} // 生成脚本引用
public IEnumerable<ScriptReference> GetScriptReferences()
{
yield return new ScriptReference("MapControl.GoogleMap.js", this.GetType().Assembly.FullName);
}
}
}
这个是GoogleMap.js
/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("MapControl");MapControl.GoogleMap = function (element) {
MapControl.GoogleMap.initializeBase(this, [element]); this._zoom = null;
this._centerLatitude = null;
this._centerLongitude = null;
// this._ers = null; this._mapObj = null;
}MapControl.GoogleMap.prototype = {
initialize: function () {
MapControl.GoogleMap.callBaseMethod(this, 'initialize'); // 在此处添加自定义初始化
this.createMap();
},
dispose: function () {
//在此处添加自定义释放操作
MapControl.GoogleMap.callBaseMethod(this, 'dispose');
},
get_zoom: function () {
return this._zoom;
},
set_zoom: function (value) {
if (this._zoom !== value) {
this._zoom = value;
this.raisePropertyChanged("zoom");
}
},
get_centerLatitude: function () {
return this._centerLatitude;
},
set_centerLatitude: function (value) {
if (this._centerLatitude !== value) {
this._centerLatitude = value;
this.raisePropertyChanged("centerLatitude");
}
},
get_centerLongitude: function () {
return this._centerLongitude;
},
set_centerLongitude: function (value) {
if (this._centerLongitude !== value) {
this._centerLongitude = value;
this.raisePropertyChanged("centerLongitude");
}
},
createMap: function () {
// Set the center point, zoom, and type of map
var centerPoint = new google.maps.LatLng(this.get_centerLatitude(), this.get_centerLongitude());
var options = {
zoom: this.get_zoom(),
center: centerPoint,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create the map, using the above options
this._mapObj = new google.maps.Map(this._element, options);
}
}
MapControl.GoogleMap.registerClass('MapControl.GoogleMap', Sys.UI.Control);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();这个是ASP.NET网站Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MapControlTest._Default" %><%@ Register Namespace="MapControl" TagPrefix="mc" Assembly="MapControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<div>
<mc:GoogleMap ID="GoogleMap1" runat="server" CenterLatitude="36.1658" CenterLongitude="-86.7844"
Width="500" Height="500">
</mc:GoogleMap>
</div>
</form>
</body>
</html>就是这三部分代码
你好,我把它发布成资源了,麻烦你帮我看一下,谢谢
http://download.csdn.net/detail/i_popular/5783809
[assembly: System.Web.UI.WebResource("MapControl.GoogleMap.js", "application/x-javascript")]