1

我在我的 on事件上使用Ajax Accordion了控件,我想设置我在 java 脚本中设置的控件属性。Master PagePage_LoadSelectedIndexAccordion

我的问题是每次HiddenField1.Value = " "Page_Load的值都没有。我没有得到我在 java 脚本中设置的隐藏字段的值,而是得到什么或空字符串。

下面是隐藏字段

<asp:HiddenField ID="HiddenField1" runat="Server"  />

注意:(1)我已经HiddenField完成了我的任务。 (2)我这样做是因为Ajax Accordion在回发后丢失了当前窗格。

<script type="text/javascript">
        function pageLoad()
         {
            $find('<%= UserAccordion.ClientID %>' + '_AccordionExtender').add_selectedIndexChanged(onAccordionPaneChanged); 
        }

       function onAccordionPaneChanged(sender, eventArgs) 
         { 
           var selPane = sender.get_SelectedIndex();
           document.getElementById('<%=HiddenField1.ClientID%>').value = selPane;
           //alert("SelectedIndex:" + selPane  ); This message fires nicely so i have confirmed that this event work
         }
    </script>

.vb以下是我在文件中的后端代码

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If HiddenField1.Value = "" Then
        Else

            UserAccordion.SelectedIndex = HiddenField1.Value

        End If
End Sub

编辑: 手风琴控制代码。

<ajax:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
                            HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent"
                            FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250"
                            FramesPerSecond="40" RequireOpenedPane="false" AutoSize="None"  
                            Width="220px" >
                            <Panes >
                                <ajax:AccordionPane ID="AccordionPane1"  runat="server" >
                                    <Header>
                                        <a href="#" class="href">ST-ERP Modules</a></Header>
                                    <Content>
                                        <asp:Panel ID="UserReg" runat="server">
                                            <asp:TreeView runat="server" ID="treeMainMenu" DataSourceID="SiteMapDataSource1"
                                                NodeIndent="10" Width="150px" OnTreeNodeDataBound="treeMainMenu_TreeNodeDataBound">
                                                <ParentNodeStyle Font-Bold="False"></ParentNodeStyle>
                                                <HoverNodeStyle ForeColor="#447BD4" Font-Underline="True"></HoverNodeStyle>
                                                <SelectedNodeStyle HorizontalPadding="0px" ForeColor="#DD5555" VerticalPadding="0px"
                                                    Font-Bold="True" Font-Underline="True"></SelectedNodeStyle>
                                                <NodeStyle NodeSpacing="0px" HorizontalPadding="0px" ForeColor="#447BD4" VerticalPadding="0px"
                                                    Font-Size="8pt" Font-Names="Verdana"></NodeStyle>
                                            </asp:TreeView>
                                        </asp:Panel>
                                    </Content>
                                </ajax:AccordionPane>
                                <ajax:AccordionPane ID="AccordionPane2" runat="server">
                                    <Header>
                                        <a href="#" class="href">User Detail</a></Header>
                                    <Content>
                                        <asp:Panel ID="Panel1" runat="server">
                                            <asp:TreeView runat="server" ID="TreeView1" DataSourceID="SiteMapDataSource2" NodeIndent="10"
                                                Width="150px">
                                                <ParentNodeStyle Font-Bold="False"></ParentNodeStyle>
                                                <HoverNodeStyle ForeColor="white" Font-Underline="True"></HoverNodeStyle>
                                                <SelectedNodeStyle HorizontalPadding="0px" ForeColor="#DD5555" VerticalPadding="0px"
                                                    Font-Bold="True" Font-Underline="True"></SelectedNodeStyle>
                                                <NodeStyle NodeSpacing="0px" HorizontalPadding="0px" ForeColor="White" VerticalPadding="0px"
                                                    Font-Size="8pt" Font-Names="Verdana"></NodeStyle>
                                            </asp:TreeView>
                                        </asp:Panel>
                                    </Content>
                                </ajax:AccordionPane>
                                <ajax:AccordionPane ID="AccordionPane3" runat="server">
                                    <Header>
                                        <a href="#" class="href">Job Details</a>
                                    </Header>
                                    <Content>
                                        <asp:Panel ID="Panel2" runat="server">
                                            ddddddddddddd</asp:Panel>
                                    </Content>
                                </ajax:AccordionPane>
                            </Panes>
                        </ajax:Accordion>
4

3 回答 3

1

尝试在两个树视图的TreeNodeDataBound事件处理程序中清除节点的 NavigateUrl 属性:

protected void treView_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
    e.Node.NavigateUrl = null;
}
于 2012-08-20T10:01:52.617 回答
0

我已经解决了这个问题,请参阅我在这篇文章 Ajax Accordion Loses Current Pane上的回答

下面如果链接断开:

Query String我确实通过使用下面的链接来解决这个问题

url="~/Opportunity/Indent.aspx?index=1" // replace 1 with your desired index

在页面加载事件中写这样的东西

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 

        Dim selectedindex As String = Request.QueryString("index")
        UserAccordion.SelectedIndex = selectedindex



    End Sub
于 2012-08-20T13:19:20.940 回答
0

我使用会话变量(即 Accordion.SelectedIndex = Session("AccordionIndex") 但 QueryString 也可以正常工作(除非您想抑制 URL 中的索引,否则会话状态会更好)

于 2014-01-02T19:47:11.310 回答