简体   繁体   English

手风琴SelectedIndexChanged时从动态创建的手风琴面板获取Pane.ID

[英]Get Pane.ID from Dynamically Created Accordion Panel When Accordion SelectedIndexChanged

I've been at this for days without success. 我已经参加了好几天没有成功了。 I have an accordion panel that is being created dynamically. 我有一个正在动态创建的手风琴面板。 One of the items in the accordion panel is the pane. 手风琴面板中的一项是窗格。 The paneis given the ID of the record in the database that is populating that pane in the accordion. 窗格被赋予在手风琴中填充该窗格的数据库中记录的ID。 As an example, if I was creating an accordion for each of the 50 states, the paneID would represent the states admission order (ie Delaware, Pane.ID = "Pane_1", New Jersey, Pane.ID = "Pane_3", Hawaii, Pane.ID = "Pane_50", etc.) 例如,如果我要为50个州中的每个州创建一个手风琴,则paneID将代表州的准入顺序(例如,特拉华州,Pane.ID =“ Pane_1”,新泽西州,Pane.ID =“ Pane_3”,夏威夷, Pane.ID =“ Pane_50”,等等)

I need to be able to pull the ID of the pane when the user selects the Accordion. 用户选择手风琴时,我需要能够拉出窗格的ID。 I've added the following script to the page that binds top the selectedIndexChange event of the accordion: 我在页面上添加了以下脚本,该脚本将手风琴的selectedIndexChange事件绑定到顶部:

        function pageLoad() {

        $find('<%= Accordion1.ClientID %>_AccordionExtender').add_selectedIndexChanged(
    accordion_selectedIndexChanged);
    };

    function accordion_selectedIndexChanged(sender, args) {
        var sinx = sender.get_SelectedIndex();
        alert(sinx);
    }

This works in that it fires when I select the Accordion pane. 当我选择“手风琴”窗格时,它将触发。 I don't know how to get the Pane.ID from this point on in the accordion_selectedIndexChanged function. 从现在开始,我不知道如何在Accordion_selectedIndexChanged函数中获取Pane.ID。

First I want to thank @zgood. 首先,我要感谢@zgood。 While I didn't find what I was looking for in the methods, it was what I DIDN'T find. 虽然我没有在方法中找到所需内容,但我找不到。 I discovered that I couldn't see a Pane ID, BUT I could see a Heading ID. 我发现我看不到窗格ID,但可以看到标题ID。 Using the information in the following links I was able to develop a solution: 使用以下链接中的信息,我能够开发一种解决方案:
Pass Javascript Variables value to C# 将Javascript变量值传递给C#
Accordion Selected Index Change Content 手风琴所选索引更改内容
How to Catch Accordion Pane Select Event 如何赶上手风琴窗格选择事件

Here are the general steps: 以下是一般步骤:

  • Created a hidden field 创建一个隐藏字段
  • Created a hidden button 创建一个隐藏的按钮
  • Captured the accordion change 捕获了手风琴的变化
  • Passed the selected index into the hidden field and then called the hidden buttons click event 将选定的索引传递到隐藏字段中,然后调用隐藏按钮的单击事件
  • Looked up the headercontainer ID in the code behind. 在后面的代码中查找headercontainer ID。

Here is the aspx code: 这是aspx代码:

function pageLoad() {
    $find('<%= Accordion1.ClientID %>_AccordionExtender').add_selectedIndexChanged(accordion_selectedIndexChanged);
};

function accordion_selectedIndexChanged(sender, args) {
    var control_clientId;
    var sinx = sender.get_SelectedIndex();
    if (sinx > -1) {
        var hdnfldVariable = document.getElementById('<%=hdnfldVariable.ClientID %>');
        hdnfldVariable.value = sinx;
        document.getElementById('LogEntry').click();                
    }
}

<asp:HiddenField ID="hdnfldVariable" runat="server" />
<asp:Button ID="LogEntry" runat="server" ClientIDMode="Static" OnClick="LogEntry_Click" />

And here is the Code Behind: 下面是代码:

 protected void LogEntry_Click(object sender, EventArgs e)
{
   if (hdnfldVariable.Value != "")
   {
      int i = int.Parse(hdnfldVariable.Value);
      string id = Accordion1.Panes[i].HeaderContainer.ID;
      //Do Something here
   }
}

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

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