简体   繁体   English

同一页面中多次引用的用户控件上的链接

[英]link on usercontrol referenced multiple times in same pages

I have a usercontrol with dropdown and a link beside on the usercontrol which opens popup depending on the value of dropdown 我有一个带下拉菜单的usercontrol和usercontrol旁边的链接,该链接根据dropdown的值打开弹出窗口

I have a page where I have referenced usercontrol twice using different IDs. 我有一个页面,其中使用不同的ID两次引用了usercontrol。 But my problem is when I click individual link on the page, since the link is on the usercontrol itself as well as the value of dropdown, the value of dropdown that I select $find('<%=RadComboBox1.ClientID%>').get_value(); 但是我的问题是,当我单击页面上的单个链接时,由于该链接位于用户控件本身以及下拉列表的值上,因此我选择$find('<%=RadComboBox1.ClientID%>').get_value();的下拉列表值$find('<%=RadComboBox1.ClientID%>').get_value(); is same for both cases, or finds from the last element 两种情况都相同,或者从最后一个元素中查找

it coz the ID of RadComboBox1 is not related to the page rather its related to usercontrol now, so it will have same ID and will get the same value for both popup link 它因为RadComboBox1的ID与页面无关,而现在与用户控件相关,所以它将具有相同的ID,并且两个弹出链接的值都相同

How do I get the link working correctly?? 如何使链接正常工作?

UserControl 用户控件

<script type="text/javascript">
function openPopUp() {
        var ddlValue = $find('<%=RadComboBox1.ClientID%>').get_value();

        if (ddlValue.length <= 0) {
            alert('Please Select a Vendor');
        }
        else {
            var jsURL = "/Open.aspx?id=" + ddlValue;
            return OpenPOPWindow(jsURL, 550, 1250, 340, 160);
        }
    }
</script>

<telerik:RadComboBox runat="server" ID="RadComboBox1" Height="190px" OnClientSelectedIndexChanged="javascript:openPopUp();" >
<a runat="server" id="lnkPopUp" visible="false"  href="javascript:void(0);">View Data</a>

Are you sure it gets the same ID? 您确定它具有相同的ID吗? Because it shouldn't. 因为它不应该。

Why don't you update it to 你为什么不更新到

javascript:openPopUp(this);

or add from code-behind: 或从代码后面添加:

RadComboBox1.OnClientSelectedIndexChanged = "openPopUp('" + RadComboBox1.ClientID + "')";

This means that openPopUp will always have the correct reference to you current combo box (first example) or combo box id (second example). 这意味着openPopUp将始终正确引用当前的组合框(第一个示例)或组合框ID(第二个示例)。

LATER EDIT: 之后编辑:

I've just made some tests. 我刚刚做了一些测试。

First, I created a user control with the following code: 首先,我使用以下代码创建了一个用户控件:

Options here: 
<asp:DropDownList runat="server" ID="ddlOptions">
    <asp:ListItem Text="option 1"></asp:ListItem>
    <asp:ListItem Text="option 2"></asp:ListItem>
    <asp:ListItem Text="option 3"></asp:ListItem>
</asp:DropDownList> 
<a href="javascript:linkit('<%=ddlOptions.ClientID%>')">Link here</a>

Then I created a page with: 然后,我创建了一个页面:

    <uc1:test runat="server" ID="test1" /><br />
    <uc1:test runat="server" ID="test2" />

    <script language="javascript" type="text/javascript">
        function linkit(id)
        {
            alert(document.getElementById(id).value);
        }
    </script>

Where uc1:test is the control described earlier. 其中uc1:test是前面描述的控件。

If I select different options on the dropdown list and click the link, I get the correct selected options (different for each link). 如果我在下拉列表中选择其他选项并单击链接,则将获得正确的所选选项(每个链接都不同)。

Isn't this the same problem you are having? 这不是您遇到的同样的问题吗?

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

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