- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
"?-6ren"> "?-有没有办法在外部 javascript 文件中使用“”? 如果我使用代码 在我的 as(c/p)x 页面内的脚本标记中,它工作正常。在呈现的页面上,ClientID 已解析。但是,如果我放入一个外部-6ren">
有没有办法在外部 javascript 文件中使用“<%= someObject.ClientID %>”?
如果我使用代码
<%= someObject.ClientID %>
在我的 as(c/p)x 页面内的脚本标记中,它工作正常。在呈现的页面上,ClientID 已解析。但是,如果我放入一个外部 JS 文件并添加:
事实并非如此。有没有办法做到这一点,或者我是否坚持将该代码留在 as(c/p)x 文件中?
附带问题 -- 在你的标记文件中执行 <%=... %> 的行为叫什么?
最佳答案
如果你真的想这样做,你可以执行以下操作
<%@ Page ContentType="text/javascript" Language="C#" AutoEventWireup="false" %>
<%@ OutputCache Duration="86400" Location="Any" VaryByParam="None" %>
var time = "<%= DateTime.Now.ToString() %>";
alert(time);
然后在你的页面中引用它
<script src="Scripts/file.aspx" type="text/javascript"></script>
Note When using mentioned method, the only way to pass target page controls client-ids, is to store client id as string in a public property, and then reference it using new instance of that page
如果唯一让您这样做的是客户端 ID,那么您可以使用以下 ASP.NET 4 功能
<any-tag ID="myCustomId" runat="server" ClientIDMode="Static" />
您还可以将所有客户端 ID 放在 C# 类中,然后使用 JSON 将其序列化并在脚本标记中呈现它,这对于版本 4 之前的 ASP.NET 来说可能是一种明智的方式。
Note using serialization method you have possibility to change any tag ids without worrying about javascript element usages, remember that this is not even possible with ASP.NET 4 ClientIDMode
页面代码文件
public partial class About : System.Web.UI.Page
{
...
protected string GetTagIds()
{
return new JavaScriptSerializer()
.Serialize(new
{
myButton = Button1.ClientID,
myCalendar = Calendar1.ClientID
});
}
...
}
页面-ASPX
<script type="text/javascript">
var IDs = <%= GetTagIds() %>;
</script>
任何地方
<script type="text/javascript">
IDs.myCalendar.doSomthing...
</script>
还有另一种选择,您可以将所有 javascript 文件传递给 ASP.NET 处理程序,但我不推荐这样做,因为只有一个 javascript 文件会使 asp.net 处理程序忙碌。
这是一个内联代码定义,您可以在其中执行代码:
<% Response.Write("Hi"); %>
<% while(i < 0) { %>
<%
Response.Write(i.ToString());
i++;
%>
<%}%>
Note You have to include ';' on end of each statement when using inline code with C# language, you can change inline language using page directive language attribute
这个相当于调用Response,自己写,看:
<%= "Hi" %> equals to <% Response.Write("Hi"); %>
Note You shouldn't include ';' when using inline expression
这个等于:
Response.Write(HttpUtility.HtmlEncode("<script type="text/javascript">alert('XSS');</script>"))
并且出于安全原因使用 --XSS,任何对此输入的 HTML 都会输出 HTML 编码的文本,可以安全地在页面中显示用户输入的内容。
Note You shouldn't include ';' when using encoded inline expression
这是一个表达式,您可以使用它来绑定(bind)来自 ConnectionStrings、Resources 和 AppSettings 的值
表达式前缀的可能性是
expressionField 是你需要的指定expressionPrefix 的属性,见:
// AppSettings
<asp:Label ... Text="<%$ AppSettings: version %>" />
// ConnectionStrings
<asp:SqlDataSource ... ConnectionString="<%$ ConnectionStrings:dbConnectionString %>" />
// Resources
<asp:Label ... Text="<%$ Resources: Messages, Welcome %>" />
Note You shouldn't include ';' and you can use expressions only on ASP.Net controls attributes
您可以在支持数据绑定(bind)的控件内的任何位置使用它,通常由 Eval 和 Bind 方法使用。
<asp:DropDownList SelectedValue='<%# Bind("CategoryID") %>'
DataSourceID="CategoriesDataSource"
DataTextField="CategoryName"
DataValueField="CategoryID"
runat="Server" />
使用绑定(bind),您可以在 ASP.NET 控件的指定属性上设置双向绑定(bind),请参阅提到的下拉菜单,它使用绑定(bind)意味着如果最终用户选择一个值然后提交页面,下拉菜单将不会丢失其选定的值。
仅将 Eval 用于显示数据。
<asp:FormView ...>
<ItemTemplate>
<a href='Eval("Link")'>Eval("LinkText")</a>
</ItemTemplate>
</asp:FormView>
<%@ Page ...%>
This one is Page Directive
<%@ OutputCache...%>
This one is OutputCache Directive and so on...
关于javascript - 有没有办法在外部 javascript 文件中使用 "<%= someObject.ClientID %>"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6542079/
我在核心 3.1 中使用谷歌身份验证。以前,我的代码运行良好,但在使用系统格式后,项目出现异常。*ArgumentException:必须提供“ClientId”选项。 (参数'ClientId')M
这是 .aspx 文件中的代码 Login Again function Validate() { if (document.getEle
我希望能够让各个用户使用 SignalR 相互发送消息,因此我需要发送到特定的客户端 ID。如何在 session 开始时为特定用户定义客户端 ID - 例如用户的 GUID 主键? 最佳答案 将 I
我正在尝试获取数据表中组件的客户端 ID。问题是 jsf 自动将行索引放在组件 id 之前,即 Update 对于第二行中的链接(索引 = 1)。 我正在使用以下方法来获取 clientId
我在页面上有 7 个 7 周的复选框和 7 天的单独时间选择器。选中复选框后,我想显示该工作日的时间选择器,如果未选中,我想隐藏相应的时间选择器 我已经使用以下代码来获取它,它也能正常工作。 func
我得到了一个我绑定(bind)到转发器的用户控件列表。 用户控件:(示例)“AppProduct” 转发器:
我在 Repeater 的 ItemTemplate 中有一个 TextBox,它也在 ItemTemplate 中。 服务器端我有: protected void txtValorMaterialA
由于指定clienID只是类MqttAndroidClient中的一个特性,在使用类IMqttClient和时不能指定IMqttAsynchClient. 连接具有唯一ID 的客户端的真正目的是什么?
我们在 Google Analytics 中定义了三个自定义维度: ClientId (dimension1): session 范围 SessionId (dimension2): session
我有一个中继器,里面有一些控件,其中一个是文本框。我正在尝试使用 jquery 获取文本框,我的代码如下所示: $("#").click(function (event) {}); 但我总是得到 nu
我有一个应用程序将由两个不同的实体使用,每个实体都有自己的 Azure Active Directory。 最初,我使用的代码是: var msalConfig = { auth: {
有谁知道在 Azure 中哪里可以找到我的 Azure Active Directory Graph 客户端 ID?我已经在 Azure 内部到处搜索过,但仍然没有运气。或者是否有人知道 powers
我在 .ascx 用户控件中遇到 扩展问题。 我有一个 .js 文件,其中包含 JavaScript 函数: function doSomething(objectId) { ... } 我
我正在尝试 Spring OAuth2 库的非常基本的实现;但是,当我向服务器发送请求时,我收到以下错误: { "error": "invalid_client", "error_descriptio
我有几个应该处理单个 bean 产生的不同类型错误的元素。现在,我从浏览器获取的某个元素的 clientID 始终相同,因为内部没有生成的 id(总共 3 个 ID)。 无论我将哪个 clientID
我有一个组合组件,它捆绑了一些输入字段。该组件将在页面上多次使用,并包含一个按钮,用于复制其中另一个组件的值。为此,我需要通过其 clientId 访问其中一个 sibling 作为 的目标 我的问
我试图在文档中找到它,但我没有在任何地方看到它。 在 CometD 中,clientId 的生命周期是多久? 因此,客户端登录并成功握手。现在他们有一个与服务器上的 session 关联的 clien
我可以获得所有 jms 主题订阅者的 ClientID 吗?我使用 Jboss AS 6 (HornetQ)。 当然,我可以向他们所有人发送查询并阅读回复,但我正在寻找更优雅的解决方案。 最佳答案 通
我想在动态生成的控件中设置所需的 ClientID。如果您有任何想法将所需的 ClientID 设置为控件而不是告诉我,则 ClientID 是只读的 最佳答案 这只能在 .Net 4 及更高版本中完
我在网格控件中有一个文本框控件。我想使用带有“”之类的 javascript 获取 textBox 的 clientID。但是我收到一条错误消息,指出当前上下文中不存在 txtBox。文本框以编程方式
我是一名优秀的程序员,十分优秀!