使用更新面板(更新面板外部的按钮)时,未触发Click事件

时间:2013-02-18 06:54:12

标签: c# asp.net ajax

这里我要准备一个图表,当我点击btnsearch时clickevent正在触发,但是当我添加updatepanel和Modalpopup扩展器时,这个click事件没有触发 任何帮助都是适当的

的.cs

protected void btnSearch_Click(object sender, EventArgs e)
    {
        if ((ddlEmp.SelectedValue != "0") & (dtFrom.Text.Trim() != "") & (dtTo.Text.Trim() != ""))
        {

            objWork.FK_EmployeeID = Convert.ToDecimal(ddlEmp.SelectedValue);

            IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
            String datetime = dtFrom.Text.Trim();
            DateTime dt = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
            objWork.Fromdate = dt;


            provider = new System.Globalization.CultureInfo("en-CA", true);
            datetime = dtTo.Text.Trim();
            dt = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
            objWork.Todate = dt;

            DataTable dtbl = objWork.Chart_ProjectWise_FilterWith_Emp_Date();
            // int i = ds.Tables[0].Rows.Count;
            ProjectWise.DataSource = dtbl;
            ProjectWise.Legends.Add("Percentage").Title = "Work duration of employees";
            // here i am giving the title of the x-axis
            ProjectWise.ChartAreas["ChartArea1"].AxisX.Title = "Project Name";
            // here i am giving the title of the y-axis
            ProjectWise.ChartAreas["ChartArea1"].AxisY.Title = "Duration";
            // here i am binding the x-axisvalue with the chart control
            ProjectWise.Series["Hours"].XValueMember = "ProjectName";
            // here i am binding the y-axisvalue with the chart control
            ProjectWise.Series["Hours"].YValueMembers = "Duration";
            ProjectWise.DataBind();
        }
    }

的.aspx

  <asp:Panel ID="Panel2" runat="server" Height="237px" Width="400px" BorderColor="WindowFrame"
                                BorderStyle="Solid" BorderWidth="2" BackColor="White">
                                <asp:Panel ID="Panel3" runat="server" Height="30px" BackColor=" #E6F0F3" HorizontalAlign="Center"
                                    CssClass="TopPanel">
                                    <asp:Label ID="Label1" runat="server" Text="Change Password" ForeColor="#1B548D" Font-Bold="True"
                                        Font-Size="Medium"></asp:Label>
                                </asp:Panel>
                                <br />

                                <asp:Label ID="lblInvalid" runat="server" ForeColor="Red" Font-Size="Small"></asp:Label>
                                <br />

                                <table cellpadding="2" cellspacing="2">
                                    <tr>
                                        <td style="font-size: small; padding-left: 10px">
                                            EmailID
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtChEmail" runat="server" Width="250"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                                ControlToValidate="txtChEmail" ErrorMessage="*"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="font-size: small; padding-left: 10px">
                                            Old Password
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtChOldPwd" runat="server" Width="250" TextMode="Password"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                                ControlToValidate="txtChOldPwd" ErrorMessage="*"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="font-size: small; padding-left: 10px">
                                            New Password
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtChNewPwd" runat="server" Width="250" TextMode="Password"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                                ControlToValidate="txtChNewPwd" ErrorMessage="*" ></asp:RequiredFieldValidator>
                                                <br />
                                                 <asp:CustomValidator ID="CustomValidator1" 
                                                        ClientValidationFunction="PasswordValidate"
                                                        ControlToValidate="txtChNewPwd" runat="server"
                                                        ErrorMessage="Enter 6 to 12 characters."
                                                        Display="Dynamic"></asp:CustomValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="font-size: small; padding-left: 10px">
                                            Confirm Password
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtChConPwd" runat="server" Width="250" TextMode="Password"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                                                ControlToValidate="txtChConPwd" ErrorMessage="*"></asp:RequiredFieldValidator>
                                            <br />
                                            <asp:CompareValidator ID="CompareValidator1" runat="server" 
                                                ControlToCompare="txtChNewPwd" ControlToValidate="txtChConPwd" 
                                                Display="Dynamic" ErrorMessage="Passwords do not match">
                                            </asp:CompareValidator>
                                        </td>
                                    </tr>
                                </table>

                                <br />
                                 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                      <asp:Panel ID="Panel4" runat="server" BackColor="#E6F0F3" 
                                    CssClass="bottompanel" Height="28px" HorizontalAlign="Center">
                                    <asp:Button ID="btnChange" runat="server" BackColor="#1B548D" Font-Bold="true" 
                                        ForeColor="#E6F0F3" onclick="btnChange_Click" Text="Change"/>
                                    <asp:Button ID="btnCancel" runat="server" BackColor="#1B548D" Font-Bold="true" 
                                        ForeColor="#E6F0F3" Text="Cancel" onclick="btnCancel_Click" />
                                </asp:Panel>

                                 </ContentTemplate>
                               <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="btnChange" />
                                <asp:AsyncPostBackTrigger ControlID="btnCancel" />
                               </Triggers>
                                </asp:UpdatePanel>
                            </asp:Panel>

                            <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Changepwd"
                                PopupControlID="Panel2" BackgroundCssClass="backgrd" CancelControlID="btnCancel"
                                onload="ModalPopupExtender1_Load" >
                                <Animations>

                                </Animations>
                            </asp:ModalPopupExtender>
                            <asp:Panel ID="Panel1" runat="server">
                                <table>
                                    <tr>
                                        <td>
                                            <table>
                                                <tr>
                                                <td class="style1">
                                                </td>
                                                    <td>
                                                        <asp:Label ID="lblSearch" runat="server" Text="Employee Name"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlEmp" runat="server" AppendDataBoundItems="true">
                                                            <asp:ListItem Text="Select Employee" Value="0" Selected="True"></asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblDate" runat="server" Text="Date"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="dtFrom" runat="server"></asp:TextBox>
                                                        <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="dtFrom"
                                                            Format="dd/MM/yyyy">
                                                        </asp:CalendarExtender>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblTo" runat="server" Text="to"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="dtTo" runat="server"></asp:TextBox>
                                                        <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="dtTo"
                                                            Format="dd/MM/yyyy">
                                                        </asp:CalendarExtender>
                                                    </td>
                                                    <td>
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnSearch" runat="server" Text="Prepare chart" ToolTip="Filter" OnClick="btnSearch_Click" />
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center">
                                            <asp:Chart runat="server" ID="ProjectWise" Width="900" Height="350" ImageStorageMode="UseImageLocation"
                                                Palette="Berry" PaletteCustomColors="Teal; DarkViolet">
                                                <BorderSkin BackColor="Transparent" PageColor="Transparent" SkinStyle="Emboss" />
                                                <Series>
                                                    <asp:Series Name="Hours" IsValueShownAsLabel="True" IsVisibleInLegend="true" LabelBorderColor="Transparent"
                                                        YValuesPerPoint="20" Color="Transparent" LabelBorderWidth="0" Palette="Pastel">
                                                    </asp:Series>
                                                </Series>
                                                <ChartAreas>
                                                    <asp:ChartArea Name="ChartArea1" BackColor="White">
                                                        <AxisY>
                                                            <MajorGrid LineColor="Gainsboro" />
                                                        </AxisY>
                                                        <AxisX>
                                                            <MajorGrid LineColor="Gainsboro" />
                                                        </AxisX>
                                                        <AxisX2>
                                                            <MajorGrid LineColor="Gainsboro" />
                                                        </AxisX2>
                                                        <AxisY2>
                                                            <MajorGrid LineColor="Gainsboro" />
                                                        </AxisY2>
                                                        <Area3DStyle Enable3D="true" />
                                                    </asp:ChartArea>
                                                </ChartAreas>
                                            </asp:Chart>

                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>

但是当我将以下代码添加到.aspx 时,点击事件未触发

  <asp:Panel ID="Panel2" runat="server" Height="237px" Width="400px" BorderColor="WindowFrame"
                        BorderStyle="Solid" BorderWidth="2" BackColor="White">
                        <asp:Panel ID="Panel3" runat="server" Height="30px" BackColor=" #E6F0F3" HorizontalAlign="Center"
                            CssClass="TopPanel">
                            <asp:Label ID="Label1" runat="server" Text="Change Password" ForeColor="#1B548D" Font-Bold="True"
                                Font-Size="Medium"></asp:Label>
                        </asp:Panel>
                        <br />

                        <asp:Label ID="lblInvalid" runat="server" ForeColor="Red" Font-Size="Small"></asp:Label>
                        <br />

                        <table cellpadding="2" cellspacing="2">
                            <tr>
                                <td style="font-size: small; padding-left: 10px">
                                    EmailID
                                </td>
                                <td>
                                    <asp:TextBox ID="txtChEmail" runat="server" Width="250"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                        ControlToValidate="txtChEmail" ErrorMessage="*"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-size: small; padding-left: 10px">
                                    Old Password
                                </td>
                                <td>
                                    <asp:TextBox ID="txtChOldPwd" runat="server" Width="250" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                        ControlToValidate="txtChOldPwd" ErrorMessage="*"></asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-size: small; padding-left: 10px">
                                    New Password
                                </td>
                                <td>
                                    <asp:TextBox ID="txtChNewPwd" runat="server" Width="250" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                        ControlToValidate="txtChNewPwd" ErrorMessage="*" ></asp:RequiredFieldValidator>
                                        <br />
                                         <asp:CustomValidator ID="CustomValidator1" 
                                                ClientValidationFunction="PasswordValidate"
                                                ControlToValidate="txtChNewPwd" runat="server"
                                                ErrorMessage="Enter 6 to 12 characters."
                                                Display="Dynamic"></asp:CustomValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-size: small; padding-left: 10px">
                                    Confirm Password
                                </td>
                                <td>
                                    <asp:TextBox ID="txtChConPwd" runat="server" Width="250" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                                        ControlToValidate="txtChConPwd" ErrorMessage="*"></asp:RequiredFieldValidator>
                                    <br />
                                    <asp:CompareValidator ID="CompareValidator1" runat="server" 
                                        ControlToCompare="txtChNewPwd" ControlToValidate="txtChConPwd" 
                                        Display="Dynamic" ErrorMessage="Passwords do not match">
                                    </asp:CompareValidator>
                                </td>
                            </tr>
                        </table>

                        <br />
                         <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                              <asp:Panel ID="Panel4" runat="server" BackColor="#E6F0F3" 
                            CssClass="bottompanel" Height="28px" HorizontalAlign="Center">
                            <asp:Button ID="btnChange" runat="server" BackColor="#1B548D" Font-Bold="true" 
                                ForeColor="#E6F0F3" onclick="btnChange_Click" Text="Change"/>
                            <asp:Button ID="btnCancel" runat="server" BackColor="#1B548D" Font-Bold="true" 
                                ForeColor="#E6F0F3" Text="Cancel" onclick="btnCancel_Click" />
                        </asp:Panel>

                         </ContentTemplate>
                       <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnChange" />
                        <asp:AsyncPostBackTrigger ControlID="btnCancel" />
                       </Triggers>
                        </asp:UpdatePanel>
                    </asp:Panel>

                    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Changepwd"
                        PopupControlID="Panel2" BackgroundCssClass="backgrd" CancelControlID="btnCancel"
                        onload="ModalPopupExtender1_Load" >
                        <Animations>

                        </Animations>
                    </asp:ModalPopupExtender>

2 个答案:

答案 0 :(得分:0)

请在

中插入更新面板
 <asp:Panel ID="Panel1" runat="server">

然后添加表格代码

<table>
                                <tr>
                                    <td>
                                        <table>
                                            <tr>
                                            <td class="style1">
                                            </td>
                                                <td>
                                                    <asp:Label ID="lblSearch" runat="server" Text="Employee Name"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:DropDownList ID="ddlEmp" runat="server" AppendDataBoundItems="true">
                                                        <asp:ListItem Text="Select Employee" Value="0" Selected="True"></asp:ListItem>
                                                    </asp:DropDownList>
                                                </td>
                                                <td>
                                                    <asp:Label ID="lblDate" runat="server" Text="Date"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="dtFrom" runat="server"></asp:TextBox>
                                                    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="dtFrom"
                                                        Format="dd/MM/yyyy">
                                                    </asp:CalendarExtender>
                                                </td>
                                                <td>
                                                    <asp:Label ID="lblTo" runat="server" Text="to"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="dtTo" runat="server"></asp:TextBox>
                                                    <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="dtTo"
                                                        Format="dd/MM/yyyy">
                                                    </asp:CalendarExtender>
                                                </td>
                                                <td>
                                                </td>
                                                <td>
                                                    <asp:Button ID="btnSearch" runat="server" Text="Prepare chart" ToolTip="Filter" OnClick="btnSearch_Click" />
                                                </td>
                                                <td>
                                                    <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" />
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center">
                                        <asp:Chart runat="server" ID="ProjectWise" Width="900" Height="350" ImageStorageMode="UseImageLocation"
                                            Palette="Berry" PaletteCustomColors="Teal; DarkViolet">
                                            <BorderSkin BackColor="Transparent" PageColor="Transparent" SkinStyle="Emboss" />
                                            <Series>
                                                <asp:Series Name="Hours" IsValueShownAsLabel="True" IsVisibleInLegend="true" LabelBorderColor="Transparent"
                                                    YValuesPerPoint="20" Color="Transparent" LabelBorderWidth="0" Palette="Pastel">
                                                </asp:Series>
                                            </Series>
                                            <ChartAreas>
                                                <asp:ChartArea Name="ChartArea1" BackColor="White">
                                                    <AxisY>
                                                        <MajorGrid LineColor="Gainsboro" />
                                                    </AxisY>
                                                    <AxisX>
                                                        <MajorGrid LineColor="Gainsboro" />
                                                    </AxisX>
                                                    <AxisX2>
                                                        <MajorGrid LineColor="Gainsboro" />
                                                    </AxisX2>
                                                    <AxisY2>
                                                        <MajorGrid LineColor="Gainsboro" />
                                                    </AxisY2>
                                                    <Area3DStyle Enable3D="true" />
                                                </asp:ChartArea>
                                            </ChartAreas>
                                        </asp:Chart>

                                    </td>
                                </tr>
                            </table>

从搜索按钮发回帖子。

答案 1 :(得分:0)

请参阅下面的帖子。它说在加载到更新面板中时,asp.net验证脚本无法正确加载。

http://jeffreypaarhuis.com/2011/08/08/validation-not-working-in-updatepanel/