繁体   English   中英

我们可以使用javascript访问ASP.Net的Web用户控件的子控件吗

[英]Can we access ASP.Net's web user control 's child controls using javascript

我有一个网络用户控件。 当我们在另一个页面中使用它时,我想知道如何使用java脚本访问其子控件。

假设我的控件如下:

  <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCS.ascx.cs" Inherits="UCS" %>
        <asp:Panel ID="rbtnPanel" runat="server">
        <asp:RadioButton ID="rbtnEn" runat="server" GroupName="scan" Checked="true" Text="Entire" style="margin-left: -7px;"/>
        <asp:RadioButton ID="rbtnCu" runat="server" GroupName="scan" Text="Custom" style="position: absolute; margin-left: 2px;"/>
         </asp:Panel>

更新:

我在页面中将其添加为:Try.aspx

 <%@ Register Src="~/UserControls/UCS.ascx" TagName="UCS" TagPrefix="ucSc" %>
 <table>
 <tr>
 <td>
          <usSc:UCS id="UCS1" runat="server" />
 </td>
 </tr>
 </table>

try.aspx:javascript:

    $(document).ready(function() {
    setPageLayout(2, 0, true);
    startTimer();
         }

  function startTimer()
   {
   alert(document.getElementById("<%= rbtnCu.ClientID %>").checked);
   }

因此,如果我通过注册在另一个页面中使用此控件。 如何访问该Try.aspx页的javascript部分中的RadioButton。

提前致谢!

您可以使用id选择器 ,因为单选按钮的ClientIDMode不是静态的,您将不得不使用ClientID,因为asp.net生成的ID并非服务器ID。

rbrbtnEn =  document.getElementById(('<%= rbtnEn.ClientID %>');

获取检查状态

alert(document.getElementById('<%= rbtnEn.ClientID %>').checked);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM