如何访问RUNAT ="服务器"使用JavaScript ASP元素? [英] How can I access runat="server" ASP element using javascript?

查看:134
本文介绍了如何访问RUNAT ="服务器"使用JavaScript ASP元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎每个人都这样做(在code职位等)...但我不知道'如何:(

It seems everyone is doing this (in code posts etc.)...but I dont' know how :(

每当我尝试使用JavaScript来操纵一个asp的元素,我收到了元素为空或文件是不确定的等错误.....

whenever i try to manipulate an asp element using javascript i get a "element is null" or "document is undefined" etc. error.....

JavaScript的通常工作得很好,...但只有当我添加=服务器属性不元素似乎看不到我的JavaScript。

javascript works fine usually,...but only when i add the runat="server" attribute does the element seem invisible to my javascript.

任何建议,将AP preciated

any suggestions would be appreciated

谢谢,安德鲁

推荐答案

什么是可能发生的是,你的元素/控制是在其中充当命名容器(母版页的ITemplate,向导等),一个或多个ASP.NET控件,这也是造成其ID更改。

What's probably happening is that your element/control is within one or more ASP.NET controls which act as naming containers (Master page, ITemplate, Wizard, etc), and that's causing its ID to change.

您可以使用查看源文件在浏览器中,以确认这是什么发生在呈现的HTML。

You can use "view source" in your browser to confirm that's what's happening in the rendered HTML.

如果您的JavaScript是在ASPX页面,最简单的方法来暂时解决就是为的使用元素的ClientID属性。例如,如果你有,你想通过JS来参一控名为TextBox1的:

If your JavaScript is in the ASPX page, the easiest way to temporarily work around that is to use the element's ClientID property. For example, if you had a control named TextBox1 that you wanted to reference via JS:

var textbox = document.getElementById('<%= TextBox1.ClientID %>');

这篇关于如何访问RUNAT =&QUOT;服务器&QUOT;使用JavaScript ASP元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆