有没有办法从JavaScript调用Web服务?我知道你可以添加一个脚本管理器来引入Web服务,但是一旦我做完了,我就无法弄清楚如何从javascript访问这些函数.
谢谢,
马特
我们正在尝试使以下方案工作:
我们使用asp:scriptmanager/CompositeScripts将我们的脚本组合成几个脚本块,但是在每次部署到测试系统之后,测试人员都无法获得css和javascript(浏览器缓存)的更新版本.对于CSS,我们已经定义了自己的css用户控件,它将一个Siteversion参数"?v = 1.0.190"附加到css url.此版本转换在web.config/appsettings中定义,并在每次部署时都会受到影响.
我们希望能够为javascripts使用相同的策略,但到目前为止我还没有取得任何成功.渲染脚本标记时.Scriptmanager渲染
<script src="/ScriptResource.axd?d=..." type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
鉴于当前配置的siteversion是1.0.190,我希望它呈现
<script src="/ScriptResource.axd?d=...&v=1.0.190" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
如何从脚本管理器获取"脚本"html输出,以便我可以更改它?它似乎不存在于Render,RenderChildren或RenderControl中呈现的内容中
你的安德烈亚斯
我有一个MVC4/Web API项目,我创建了一个使用Ajax消耗Web API的测试页面.测试进展顺利,所以我开始在UI上工作.我需要做的一件事是使用从Web API返回的数据填充一些表单控件.我为此使用了JQuery.
现在,当我运行应用程序并提交表单时,我收到一个错误,指示页面已更新:
Invalid postback or callback argument. Event validation is enabled using <pages
enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %>
in a page. For security purposes, this feature verifies that arguments to postback
or callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation
method in order to register the postback or callback data for validation.
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我将表单控件包装在UpdatePanel中并添加了ScriptManager控件.现在我在构建时遇到以下错误:
The type or namespace name 'ScriptManager' does not …Run Code Online (Sandbox Code Playgroud) 有没有其他方法可以在asp.net Web应用程序中显示来自后端的警报消息而不是这个.
ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage","alert('Called from code-behind directly!');", true);
Run Code Online (Sandbox Code Playgroud)
我也包括使用System.Web.UI命名空间,但仍然使用此代码获得这两个错误:
第一个错误:
'System.Web.UI.ScriptManager.RegisterStartupScript(System.Web.UI.Page,System.Type,string,string,bool)'的最佳重载方法匹配有一些无效的参数D:\ my_backup\Demos\NewShop\NewShop\API\ProductAPIController.cs 85 17 N ewShop
第二个错误:
参数1:无法从'NewShop.API.ProductAPIController'转换为'System.Web.UI.Page'D:\ my_backup\Demos\NewShop\NewShop\API\ProductAPIController .cs 85 53 NewShop
如果在页面中构建AJAX功能,为什么会要求EnablePartialRendering属性为"false"?似乎适得其反.我已经在这里阅读了一些可能想要处理的属性为false的事情.但我读过的内容毫无意义.
思考?
我只在生产中遇到AjaxToolkit日历显示错误.本地调试时,此问题不存在,日历日期选择器完美运行.所有其他帖子围绕此工具包不起作用.我担心为什么这在测试中有效但不能生成,因为我在使用ASP.NET ScriptManager的代码中的任何地方都找不到引用.
以下是"Site.Master"
<ajaxToolKit:ToolkitScriptManager runat="server">
<Scripts>
<%--Framework Scripts--%>
<%--<asp:ScriptReference Name="jquery" />--%>
<%--<asp:ScriptReference Name="jquery.ui.combined" />--%>
<asp:ScriptReference Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</ajaxToolKit:ToolkitScriptManager>
Run Code Online (Sandbox Code Playgroud)
这是使用日历功能并将Site.Master作为其MasterPageFile的页面
<asp:Label ID="DateRangeLabel" runat ="server" Text="Date Range: "></asp:Label>
<asp:TextBox ID="DateFrom" runat="server" Width="95px"></asp:TextBox>
<ajaxtoolkit:calendarextender ID="Calendarextender" runat="server" TargetControlID="DateFrom" PopupPosition="BottomLeft" Format="MM/dd/yyyy"></ajaxtoolkit:calendarextender>
<asp:TextBox ID="DateTo" runat="server" Width="95px"></asp:TextBox>
<ajaxtoolkit:calendarextender ID="Calendarextender1" runat="server" TargetControlID="DateTo" PopupPosition="BottomLeft" Format="MM/dd/yyyy"></ajaxtoolkit:calendarextender>
Run Code Online (Sandbox Code Playgroud)
这是我的Web.config文件的一部分
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" /> …Run Code Online (Sandbox Code Playgroud) 我复制了一些代码来解决在ASP.Net中进行AJAX回发后运行JavaScript的问题.不幸的是,新代码在进行构建时给了我以下错误:
The name 'ScriptManager' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
现在我以前使用过ScriptManager,为什么现在会给我带来问题呢?是不是所有ASP.Net页面都可用?毕竟我的母版页上有一个脚本管理器......
我在更新面板中使用ajax计时器控件.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
计时器应该每秒使用当前日期时间更新标签.
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
Run Code Online (Sandbox Code Playgroud)
在调试模式下一切正常,但是当我运行没有调试器的站点(CTRL + F5)或者我将站点部署到我的服务器时,计时器不会打勾.
但是当我在web.config中添加"debug = true"时,一切正常.甚至在我的服务器上.
<compilation targetFramework="4.0" debug="true">
Run Code Online (Sandbox Code Playgroud)
Internet Explorer在ScriptResource.axd中引发异常"对象不支持此操作".
我该如何解决这个问题?
编辑:我想我已经解决了.
我不知道为什么但有两件事可以解决这个问题:
我不知道这是不是一个bug.
也许有人可以解释一下.
使用:Visual Studio Express 2013 for Web编写.NET 4.5.1站点.
项目最初建立在默认的"创建新网站"模板上,因此有问题的部分由IDE添加到我的项目中,尚未编辑.
这是一个长达数周的项目,今天我开始收到与创建时添加的"罐装"项目有关的错误.到目前为止,它一直没有错误地工作.
错误消息是:
Server Error in '/' Application.
'respond' is not a valid script name. The name must end in '.js'.
Run Code Online (Sandbox Code Playgroud)
我调试了这个与我的site.master文件中的这一行直接相关:
<asp:ScriptReference Name="respond" />
Run Code Online (Sandbox Code Playgroud)
在此处查看评论此参考文献包含在我的主文件部分中:
这是IDE在创建时添加的更大的脚本引用组的一部分.
在故障排除中,我尝试添加.js; 将路径属性添加到实际文件中; 并完全评论了这条线.
添加扩展名和/或路径会导致不同的错误:
Server Error in '/' Application.
The assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' does not contain a Web resource that
has the name 'respond.js'. Make sure that the resource name is spelled correctly.
Run Code Online (Sandbox Code Playgroud)
唯一成功的故障排除是评论它但这打破了另一个关键功能:访问我的链接现在需要.ASPX扩展现在我以前可以访问我的链接而不指定我的文件上的扩展名...这是项目的默认方式是通过ide创建的,所以有了这个修复,我的链接都没有编辑,没有编辑每个链接和扩展. 不理想.
我已经尝试使用程序包管理器进行更新,但没有任何成功.我还验证了我的脚本文件夹中存在的respond.js文件,以及bootstrap等其他文件.
我在这里搜索并搜索了相当长的一段时间,但有很多不相关的结果,包含脚本管理员的摘录,结果是无穷无尽的.
我不确定需要进行更正,或者是否需要其他文件.重建我的网站没有任何效果,我已经删除了每个帖子中的"临时"文件我说它可能适用于不同但相似的问题.
对此错误的纠正措施是什么?
我收到了这个错误:
ASP.NET Ajax客户端框架无法加载
有错误:
'Sys'未定义.
错误在底部的IE中显示(错误消息),并且仅在我在服务器上运行该站点时才会出现.在我的localhost一切正常.
我搬到新服务器,我有问题.我以前的服务器一切都很好.
问题来自ajax的SCRIPTMANAGER.
我该怎么办?在web.config中的东西,还是主机公司需要安装什么东西?
ASP.NET 4,IIS 7.5
IE上丑陋的黄色三角形并不是什么令我不安的..最大的问题是脚本管理器更新pannel - 不行!
asp.net ×10
scriptmanager ×10
ajax ×4
c# ×3
javascript ×3
asp.net-ajax ×2
asp.net-mvc ×1
code-behind ×1
timer ×1
web-services ×1
webforms ×1