Thursday, 15 December 2011

Updating a single updatepanel onclick of multiple buttons


If We Want partially rendering of a part of page on click of multiple buttons then we have to add the multiple triggers for that update panel as defined in code given below



Write code on aspx file


<table style="width: 100%; background-color: #FFFFFF; height: 480px;" align="left">
        <tr valign="top" style="width: 100%">
            <td class="style8" valign="top" rowspan="3" style="background-color: #31307B; width: 20%">
                <asp:Button ID="cmdsummary" runat="server" BackColor="White" Font-Bold="True" ForeColor="#333399"
                    Height="30px"  Text="Summary" Width="222px" />
                <br />
                <asp:Button ID="cmdAdmittedPatient" runat="server" BackColor="White" Font-Bold="True"
                    ForeColor="#000099" Height="30px"  Text="Admitted Patient"
                    Width="222px" onclick="cmdAdmittedPatient_Click" />
                <br />
                <asp:Button ID="cmdRevenueReport" runat="server" BackColor="White" Font-Bold="True"
                    ForeColor="#333399" Height="30px"  Text="Revenue Report"
                    Width="222px" onclick="cmdRevenueReport_Click" />
                <br />
                <asp:Button ID="cmdPanelBilling" runat="server" BackColor="White" Font-Bold="True"
                    ForeColor="#333399" Height="30px"  Text="Panel Billing"
                    Width="222px" onclick="cmdPanelBilling_Click" />
                <br />
                <asp:Button ID="cmdCollectionReport" runat="server" BackColor="White" Font-Bold="True"
                    ForeColor="#333399" Height="30px"  Text="Daily Collection Report"
                    Width="222px" onclick="cmdCollectionReport_Click" />
                <br />
                <asp:Button ID="cmdConsulantShare" runat="server" BackColor="White" Font-Bold="True"
                    ForeColor="#333399" Height="30px"  Text="Consultant Share Report"
                    Width="222px" onclick="cmdConsulantShare_Click" />
                <br />
            </td>
            <td style="width: 80%">
                <asp:UpdatePanel ID="updtpanel" runat="server">
                    <ContentTemplate>
                        <table style="width: 113%; height: 27px;">
                            <tr>
                                <td class="style3">
                                    From Date :
                                </td>
                                <td>
                                    <asp:TextBox ID="txtFrom" runat="server"></asp:TextBox>
                                    <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFrom">
                                    </cc1:CalendarExtender>
                                </td>
                                <td class="style3">
                                    To Date :
                                </td>
                                <td>
                                    <asp:TextBox ID="txtTo" runat="server"></asp:TextBox>
                                    <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtTo">
                                    </cc1:CalendarExtender>
                                </td>
                                <td class="style17">
                                    <asp:Button ID="cmdRefersh" runat="server" Text="Refersh"></asp:Button>
                                </td>
                                <td class="style18">
                                </td>
                            </tr>
                        </table>
                        </td>
                        <td class="style16">
                        </td>
                        </tr>
                    </ContentTemplate>
                    <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="cmdsummary" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="cmdAdmittedPatient" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="cmdRevenueReport" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="cmdPanelBilling" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="cmdCollectionReport" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="cmdConsulantShare" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>


Define the events on the code behined file

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

        protected void cmdAdmittedPatient_Click(object sender, EventArgs e)
        {
            txtFrom.Text = DateTime.Now.ToString();
            txtTo.Text = DateTime.Now.ToString();

        }

        protected void cmdCollectionReport_Click(object sender, EventArgs e)
        {
            
            
            txtFrom.Text = DateTime.Now.ToString();
            txtTo.Text = DateTime.Now.ToString();
        }

        protected void cmdRevenueReport_Click(object sender, EventArgs e)
        {
            txtFrom.Text = DateTime.Now.ToString();
            txtTo.Text = DateTime.Now.ToString();
        }

        protected void cmdPanelBilling_Click(object sender, EventArgs e)
        {
             txtFrom.Text = DateTime.Now.ToString();
             txtTo.Text = DateTime.Now.ToString();
        }

        protected void cmdConsulantShare_Click(object sender, EventArgs e)
        {
             txtFrom.Text = DateTime.Now.ToString();
             txtTo.Text = DateTime.Now.ToString();
        }



Now These Two TextBox Updated On Click All The Buttons 

1 comment: