通过javascript函数引用控件 [英] Refering to controls through javascript function
问题描述
我在gridview中有一个单选按钮列,位于许多嵌套的asp表中.我希望收音机在单击时启用两个按钮.因此,我在JavaScript的以下函数中添加了此函数,但是尽管我为那些按钮打开了ClientIDMode ="Static",但它找不到我的控件.返回null.
I have a radiobutton column in a gridview, inside many nested asp tables. I want radios enable two buttons upon click. so I added this the following function an javascript but it cannot find my controls although I turned ClientIDMode="Static" for those buttons. It returns null.
<asp:GridView ID="gridView_stLists" runat="server" AutoGenerateColumns="False" CellPadding="3"
BorderStyle="NotSet" CssClass="table_layout" Width="500">
<RowStyle CssClass="table_body" />
<Columns>
<asp:TemplateField HeaderStyle-Width="20">
<ItemTemplate>
<input name="radioBtn_res" type="radio" value='<%# Eval("uri") %>' onclick="rdBtn_onClick()" />
</ItemTemplate>
<script language="javascript" type="text/javascript">
function rdBtn_onClick()
{
document.getElementById("btn_delete_list").enable=true;
document.getElementById("btn_showRes").enable=true;
}
</script>
问题可能出在脚本标签的地方吗?我把它放在内容标签下.
can the problem be from the place of script tag? I put it under content tag.
推荐答案
将您的JavaScript更改为此
Change your JavaScript to this
<script language="javascript" type="text/javascript">
function rdBtn_onClick() {
document.getElementById("<%= btn_delete_list.ClientID %>").disabled = false;
document.getElementById("<%= btn_showRes.ClientID %>").disabled = false;
}
</script>
I'm guessing that the problem is to do with INamingContainer
changing the ids of controls in the rendered HTML sent to the client.
标记中的按钮在哪里?当您查看源代码时,HTML是什么样的?
Where are the buttons in your markup? What does the HTML look like when you View Source?
这篇关于通过javascript函数引用控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!