Charlie
Charlie

Reputation: 110

Why does my asp update panel only refresh once

Hi I have an asp updatePanel which contains several asp panels. The way it should function is you click the button in the first panel it hides that panel and shows the next. That works fine the problem comes with the next panel. If I try and use either of the button controls within that panel nothing happens.

Heres the html

<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
            <ContentTemplate>
                <asp:Panel ID="pnlAppRej" runat="server" HorizontalAlign="Center" CssClass="textBox"
                    Width="85%" Visible="True">
                    <div style="text-align:left; width:90%">
                        <asp:Label ID="lblAppRej" runat="server" Text="Label"></asp:Label>
                    </div>
                    <asp:Button ID="btnApprove" runat="server" Text="Approve" CssClass="button" Style="margin-right: 20px;
                        margin-top: 10px" Width="100px" onclick="btnApprove_Click" />
                    <asp:Button ID="btnReject" runat="server" CssClass="button" Text="Reject" Style="margin-left: 20px"
                        Width="100px" onclick="btnReject_Click" />
                </asp:Panel>
                <asp:Panel runat="server" ID="pnlRejCom" Width="85%" Visible="False" CssClass="textBox">
                    <div style="text-align: left">
                        Comments<br />
                    </div>
                    <asp:TextBox ID="tbRejCom" runat="server" Height="54px" TextMode="MultiLine" Width="95%"
                        CssClass="textBox" Style="margin-top: 5px" ValidationGroup="rejCom"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbRejCom"
                        ErrorMessage="RequiredFieldValidator" ValidationGroup="rejCom">*</asp:RequiredFieldValidator>
                    <br />
                    <div style="text-align: center">
                        <asp:Button ID="btnBackRejCom" runat="server" CssClass="button" Text="Back" Style="margin-right: 20px;
                            margin-top: 10px" Width="100px" />
                        <asp:Button ID="btnDoneRejCom" runat="server" CssClass="button" Text="Done" Style="margin-left: 20px;
                            margin-top: 10px" Width="100px" ValidationGroup="rejCom" 
                            onclick="btnDoneRejCom_Click" />
                    </div>
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>

c# code

    protected void btnReject_Click(object sender, EventArgs e)
    {
         pnlRejCom.Visible = true;
         pnlAppRej.Visible = false;
    }
    protected void btnBackRejCom_Click(object sender, EventArgs e)
    {
        pnlRejCom.Visible = false;
        pnlAppRej.Visible = true;
    }

its the btnBackRejCom_Click method which doesnt seem to fire. But I have tested setting the pnlRejCom to visible and the method works fine.

Thanks in advance

Charlie

Upvotes: 0

Views: 1713

Answers (2)

Deepak Joshi
Deepak Joshi

Reputation: 1066

I have same problem so I have just added CausesValidation="False" then it works fine for me.so please add CausesValidation in btnBackRejCom button like as below

Please try it

 <asp:Button ID="btnBackRejCom" runat="server"  CausesValidation="False" CssClass="button" Text="Back" Style="margin-right: 20px;
                            margin-top: 10px" Width="100px" />

I think It works for you :)

Upvotes: 0

Krunal Patil
Krunal Patil

Reputation: 3676

your problem seems to be different. I would suggest, delete the

 protected void btnBackRejCom_Click(object sender, EventArgs e){}

and again create a new event.

This is what i tried and is working fine now.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <Triggers>
                    <asp:PostBackTrigger ControlID="btnReject" />
                    <asp:AsyncPostBackTrigger ControlID="btnBackRejCom" />
                    <asp:PostBackTrigger ControlID="btnDoneRejCom" />
                </Triggers>
                <ContentTemplate>
                    <asp:Panel ID="pnlAppRej" runat="server" HorizontalAlign="Center" CssClass="textBox"
                        Width="85%" Visible="True">
                        <div style="text-align: left; width: 90%">
                            <asp:Label ID="lblAppRej" runat="server" Text="Label"></asp:Label>
                        </div>
                        <asp:Button ID="btnApprove" runat="server" Text="Approve" CssClass="button" Style="margin-right: 20px; margin-top: 10px"
                            Width="100px" OnClick="btnApprove_Click" />
                        <asp:Button ID="btnReject" runat="server" CssClass="button" Text="Reject" Style="margin-left: 20px"
                            Width="100px" OnClick="btnReject_Click" />
                    </asp:Panel>
                    <asp:Panel runat="server" ID="pnlRejCom" Width="85%" Visible="False" CssClass="textBox">
                        <div style="text-align: left">
                            Comments<br />
                        </div>
                        <asp:TextBox ID="tbRejCom" runat="server" Height="54px" TextMode="MultiLine" Width="95%"
                            CssClass="textBox" Style="margin-top: 5px" ValidationGroup="rejCom"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbRejCom"
                            ErrorMessage="RequiredFieldValidator" ValidationGroup="rejCom">*</asp:RequiredFieldValidator>
                        <br />
                        <div style="text-align: center">
                            <asp:Button ID="btnBackRejCom" runat="server" CssClass="button" Text="Back" Style="margin-right: 20px; margin-top: 10px"
                                Width="100px" OnClick="btnBackRejCom_Click1" />
                            <asp:Button ID="btnDoneRejCom" runat="server" CssClass="button" Text="Done" Style="margin-left: 20px; margin-top: 10px"
                                Width="100px" ValidationGroup="rejCom"
                                OnClick="btnDoneRejCom_Click" />
                        </div>
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>

code behind :

protected void btnBackRejCom_Click1(object sender, EventArgs e)
    {
        pnlRejCom.Visible = false;
        pnlAppRej.Visible = true;
    }

Hope this helps. Happy Coding..!!!

Upvotes: 1

Related Questions