面板可见性开/关切换效果不起作用

时间:2012-03-14 01:34:35

标签: c# asp.net

我有一个名为lbxUpcommingEvents的ListBox。更改索引时,将触发事件处理程序以检查重复记录。如果找不到重复项,则通过显示样式的方式打开窗体视图中名为pnlAction的面板。如果发现重复,则打开另一个面板pnlActionCancel并关闭其他面板。基本上是一种toogle效果。

我已经尝试了可见属性,查看状态属性,但它不起作用,我无法弄清楚,所以再一次,我寻求集体的wizdom。这是我的代码。

protected void lbxUpcommingEvents_OnSelectedIndexChanged(object sender, EventArgs e)
{
    pnlEventsSignUp.Visible = true;
    string _selectedItemValue = lbxUpcommingEvents.SelectedValue.ToString();
    int _eventid = Convert.ToInt32(_selectedItemValue);

    Guid _memberId = Guid.Empty;
    _memberId = new Guid(Session["myId"].ToString());

    // Check for existing signup
    EventsMemberSignup _createSingup = new EventsMemberSignup();
    dsEventsSingupTableAdapters.MemberEventsTableAdapter da = new dsEventsSingupTableAdapters.MemberEventsTableAdapter();
    dsEventsSingup.MemberEventsDataTable dt = da.GetDataForDupCheck(_memberId, _eventid);

    if (dt.Rows.Count == 1)
    {
        Panel pnlAction = (Panel)(fvEventSignUp.FindControl("pnlAction"));
        //pnlAction.Visible = false;
        pnlAction.Style.Add("display","none");

        Panel pnlActionCancel = (Panel)(fvEventSignUp.FindControl("pnlActionCancel"));
        //pnlActionCancel.Visible = true;
        pnlActionCancel.Style.Remove("display");
    }
    else
    {
        Panel pnlActionCancel = (Panel)(fvEventSignUp.FindControl("pnlActionCancel"));
        //pnlActionCancel.Visible = false;
        pnlActionCancel.Style.Add("display", "none");

        Panel pnlAction = (Panel)(fvEventSignUp.FindControl("pnlAction"));
        //pnlAction.Visible = true;
        pnlAction.Style.Remove("display");
    } 
}

<div id="columnleft">
<a name="content_start" id="content_start"></a>
<div class="leftblock">
    <h2>Events Signup</h2>
    <p>               
    </p>
    <h3> Upcomming Events</h3>
    <p>
        <asp:ListBox ID="lbxUpcommingEvents" runat="server" DataSourceID="odsUpcommingEvents" 
            Rows="6" DataTextField="Title" DataValueField="id" AutoPostBack="true"
            Width="206px" OnSelectedIndexChanged="lbxUpcommingEvents_OnSelectedIndexChanged"  />
    </p>
    <h3> Members Attending</h3>
    <p>
        <asp:DataGrid ID="lboxSignedUpMembers" runat="server" DataSourceID="odsSignedUpMembers" 
            AutoPostBack="true" AutoGenerateColumns="false" RowStyle-CssClass="gridview" AlternatingRowStyle-CssClass="altbgcolor"
            Width="206px" onselectedindexchanged="lboxSignedUpMembers_SelectedIndexChanged" CssClass="gridview"
            GridLines="None"  BorderStyle="Solid" BorderWidth="1" BorderColor="Black" >
            <AlternatingItemStyle BackColor="White" />
            <Columns>
                <asp:BoundColumn DataField="Name" />
                <asp:BoundColumn DataField="Title" />
                <asp:TemplateColumn >
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblDate" Text='<%# Eval("StartTime", "{0:d}") %>' />
                    </ItemTemplate>
                </asp:TemplateColumn>
            </Columns> 
        </asp:DataGrid>
    </p>
</div>
</div>
</td>
<td align="left" >
<!--Start of right column-->
<div id="columnright">
<div class="rightblock">
    <asp:Panel ID="pnlEventsSignUpTitle" runat="server" CssClass="actionbuttons">
        <h2>Select an Event to Signup</h2>
    </asp:Panel>
    <asp:Label runat="server" ID="lblNote" ForeColor="#cc0000" Font-Bold="true" />
</div>
<div class="rightblock">
    <asp:Panel runat="server" ID="pnlEventsSignUp" visible="false">           

        <div class="dashedline" ></div>
        <asp:FormView ID="fvEventSignUp" runat="server" DataSourceID="ObjectDataSource1" 
            DataKeyNames="id" Width="100%" >
            <ItemTemplate>
                <h2>
                    <asp:HiddenField runat="server" ID="hfEventID" Value='<%# Eval("id") %>' />
                    <asp:Label Text='<%# Eval("title") %>' runat="server" ID="titleLabel" />
                </h2>
                <div class="itemdetails">
                    <br />
                    location:
                    <h3>
                        <asp:Label ID="locationLabel" runat="server" Text='<%# ShowLocationLink(Eval("locationname"),Eval("location")) %>' />
                    </h3>
                    <p>
                        <asp:Label Text='<%# Eval("starttime","{0:D}") %>' runat="server" ID="itemdateLabel" CssClass="GeneralText" />

                        <asp:Label Text='<%# ShowDuration(Eval("starttime"),Eval("endtime")) %>' runat="server" ID="Label1"  CssClass="GeneralText" />
                    </p>
                </div>
                <div class="downloadevent">
                    <a href="#">
                        <img src="images/icon_download_event.gif" alt="Download this event to your personal calendar"
                            width="15" height="26" /></a><a href='<%# "events_download.ashx?EventID=" + Convert.ToString(Eval("id")) %>'>Add
                                this event to your personal calendar</a>
                </div>
                <Club:ImageThumbnail ID="thumb1" runat="server" ImageSize="Large" PhotoID='<%# Eval("photo") %>' />
                <p>
                    <asp:Label Text='<%# Eval("description") %>' runat="server" ID="descriptionLabel" />
                </p>
                <div class="dashedline" ></div>
                <asp:Panel ID="pnlAction" runat="server" CssClass="actionbuttons" >
                    <table border="0" cellpadding="2" cellspacing="2">
                        <tr>
                            <td>
                                <asp:Label runat="server" ID="Label2" Text="Action<br />Required" Width="80px" Font-Bold="true"
                                            ForeColor="#cc0000" Font-Size="14px" />
                            </td>
                            <td>
                                <img src="images/RedArrow.jpg" alt="Red Arrow Right" />
                            </td>
                            <td>
                                <asp:CheckBox runat="server" ID="cbxCert" Height="30px" Text="Check to Confirm Attendance" /><br />
                                <asp:CustomValidator runat="server" ID="rfvConfirm" 
                                            ErrorMessage="You must check the box to continue" Font-Bold="true"
                                            ForeColor="#cc0000" ClientValidationFunction="ensureChecked" /> <br />
                                <Club:RolloverLink ID="rlnkSignUp" runat="server" Text = "I will be attending this event" 
                                        OnClick="rlnkSignUp_OnClick" ToolTip="I hereby certify that I am commiting to attending this event."
                                />
                            </td>
                        </tr>
                    </table>                                            
                </asp:Panel>
                <asp:Panel runat="server" ID="pnlActionCancel" CssClass="actionbuttons" >
                    <table border="0" cellpadding="2" cellspacing="2">
                        <tr>
                            <td>
                                <asp:Label runat="server" ID="lblDupSignup" Text="You are alredy signed up for this event" ForeColor="#cc0000" Font-Bold="true" Font-Size="14px" />
                            </td>
                            <td>

                            </td>
                            <td>
                                <asp:CheckBox runat="server" ID="cbxCancel" Height="30px" Text="Check to Cancel Attendance" /><br />
                                <asp:CustomValidator runat="server" ID="CustomValidator1" 
                                            ErrorMessage="You must check the box to continue" Font-Bold="true"
                                            ForeColor="#cc0000" ClientValidationFunction="ensureChecked" /> <br />
                                <Club:RolloverLink ID="rlnCancel" runat="server" Text="I'm cancelling my participation"
                                        OnClick="rlnCancel_OnClick" />
                            </td>
                        </tr>
                    </table>                                            
                </asp:Panel>
            </ItemTemplate>
        </asp:FormView>
    </asp:Panel>
</div>

2 个答案:

答案 0 :(得分:0)

我已将ViewStateMode设置为“已禁用”。我只是希望它不会在其他地方反击。

答案 1 :(得分:0)

如果您删除更新面板并将控件置于其中,则现有代码可能会有效。

或者,您可以在页面中创建属性,如

private bool myRowCount;
protected bool HasRowsMyData
{
      get { return myRowCount; } 
      set { myRowCount=value;  } 
}

然后在selectedIndex更改事件

if (dt.Rows.Count == 1)
{
    HasRowsMyData=true;
    //DataBind your controls here
    YourUpdatePanel.Update();
}

在面板上的aspx中,您可以像这样设置每个面板的可见属性,因此每当页面更新时,它们将根据结果打开/关闭

Visible='<%#HasRowsMyData%>'
Visible='<%#!HasRowsMyData%>'

如果你喜欢在客户端做这个我建议jQuery的切换功能 jQuey:toggle()