Gridview无法找到modalpopupextender的控件

时间:2016-09-26 03:31:53

标签: c# ajax gridview modalpopupextender

我有一个带有“View”ID =“lnkViewContact”列的gridview。点击此链接注册将显示modalpopupextender。所有行的弹出窗口类似。但是当我运行它时,我得到的错误是“找不到控制lnkViewContact”。如何解决。另一种方法是在链接点击上使用Onclick事件,但我不想为打开Popupextender做回发。以下是我的代码:

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Panel ID="pnlNoData" runat="server" align="center" Visible="false" Style="height: 300px;
                        width: auto;">
                        <h1 style="font-variant: normal; font-family: Times New Roman; font-size: 1.8em;
                            margin-left: 15px; font-weight: lighter; color: Green; margin-top: 100px;">
                            Refine your search.</h1>
                        <h1 style="font-variant: normal; font-family: Times New Roman; font-size: 1.8em;
                            margin-left: 15px; font-weight: lighter; color: Green; margin-left: 100px; margin-right: 100px;">
                            Not finding suitable candidates. </h1>
                        <cc1:ModalPopupExtender ID="mp3" runat="server" PopupControlID="pnlJobPost" BehaviorID="bvJobPost"
                            TargetControlID="lnkPostJobReq" BackgroundCssClass="mBackground" CancelControlID="btnClose">
                        </cc1:ModalPopupExtender>
                        <asp:LinkButton ID="lnkPostJobSignUp" Text="Sign Up and Post Job" Font-Size="Medium"
                            runat="server" OnClick="SignUp" Visible="false"></asp:LinkButton>
                        <asp:LinkButton ID="lnkPostJobReq" Text="Post Job Requirement" Font-Size="Medium"
                            runat="server"></asp:LinkButton>
                    </asp:Panel>
                    <asp:GridView ID="grdSearchResult" runat="server" DataKeyNames="SeekerEmail_Id, Extension"
                        OnRowDataBound="OnRowDataBound" AutoGenerateColumns="False" BorderWidth="1px"
                        BackColor="White" CellPadding="5" BorderStyle="None" BorderColor="Gray" GridLines="Both"
                        Width="100%">
                        <FooterStyle ForeColor="Black" BackColor="White"></FooterStyle>
                        <PagerStyle ForeColor="Black" HorizontalAlign="Center" BackColor="White"></PagerStyle>
                        <HeaderStyle ForeColor="White" Font-Bold="True" BackColor="Green"></HeaderStyle>
                        <Columns>
                            <asp:BoundField HeaderText="Job Skills" DataField="Primary_Skill" SortExpression="Primary_Skill"
                                ItemStyle-Width="35%" ItemStyle-HorizontalAlign="Center" ItemStyle-Wrap="true"
                                ItemStyle-CssClass="grdSearchResultbreakword"></asp:BoundField>
                            <asp:BoundField HeaderText="Resume Title" DataField="Resume_Title" SortExpression="Resume_Title"
                                ItemStyle-HorizontalAlign="Center" ItemStyle-Wrap="true" ItemStyle-Width="30%"
                                ItemStyle-CssClass="grdSearchResultbreakword"></asp:BoundField>
                            <asp:BoundField HeaderText="Exp (Years)" DataField="Experience" SortExpression="Experience"
                                ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                           
                            <asp:TemplateField HeaderText="Contact Details Email/Mobile" ItemStyle-HorizontalAlign="Center"
                                ItemStyle-Width="12%">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkViewContact" Text="View" runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Contact Details Email/Mobile" ItemStyle-HorizontalAlign="Center"
                                ItemStyle-Width="15%">
                                <ItemTemplate>
                                    <asp:Label ID="lblContact" ForeColor="DarkOrange" runat="server" Text='<%# Eval("SeekerEmail_Id").ToString() +" / "+ Eval("Contact_Number").ToString()  %>'
                                        Style="word-wrap: normal; word-break: break-all; cursor: default;"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Download Resume" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkDown" Text="Download" runat="server" OnClick="SignUp"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            
                        </Columns>
                        <SelectedRowStyle ForeColor="White" Font-Bold="True" BackColor="#008A8C"></SelectedRowStyle>
                        <RowStyle ForeColor="Black" BackColor="White"></RowStyle>
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#0000A9" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#000065" />
                    </asp:GridView>
                    <asp:LinkButton ID="lnkFake" runat="server"></asp:LinkButton>
                    <cc1:ModalPopupExtender ID="mp1" BehaviorID="behaviorIDmp1" runat="server" PopupControlID="Panl1"
                        TargetControlID="lnkViewContact" CancelControlID="btnCancel" DropShadow="true" BackgroundCssClass="modalBackground">
                    </cc1:ModalPopupExtender>
                    <asp:Panel ID="Panl1" runat="server" CssClass="modalPopup" align="center" Style="display: none;
                        height: 400px;" DefaultButton="btnRegister">
                        <%--<h1 style="font-variant: normal; font-family: Comic Sans MS; font-size: 1.5em; font-weight: lighter;
                    margin-top: 2px; margin-bottom: 2px; text-align: center; color: Blue;">
                    SIGN UP</h1>--%>
                        
                        <asp:Label ID="lblEmailId" runat="server" ForeColor="Black" Text="Email address"
                            Style="font-weight: bold; display: block; text-align: left; margin-left: 45px;
                            margin-top: 10px;"></asp:Label>
                        <asp:TextBox ID="txtEmailAddress" runat="server" class="txtFirstName" MaxLength="100"
                            name="email" TabIndex="3" value="" /><br />
                        <asp:RequiredFieldValidator EnableClientScript="true" ID="reqEmailAdress" runat="server"
                            ValidationGroup="modal" ControlToValidate="txtEmailAddress" ErrorMessage="Email Address Required"
                            Display="Dynamic" Style="color: Red;" />
                        <asp:RegularExpressionValidator ID="regEmailAddress" runat="server" ErrorMessage="Not Valid Email ID"
                            ValidationGroup="modal" Display="Dynamic" ControlToValidate="txtEmailAddress"
                            ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                        </asp:RegularExpressionValidator>
                        <asp:Label ID="lblContactNumber" runat="server" ForeColor="Black" Text="Contact Number(Don't prefix 0 or +91)"
                            Style="font-weight: bold; display: block; text-align: left; margin-left: 45px;"></asp:Label>
                        <asp:TextBox ID="txtContactNumber" runat="server" class="txtFirstName" MaxLength="15"
                            name="contact" TabIndex="6" value="" /><br />
                        <asp:RequiredFieldValidator EnableClientScript="true" ID="reqContactNumber" runat="server"
                            ValidationGroup="modal" ControlToValidate="txtContactNumber" ErrorMessage="Contact Number Required"
                            Display="Dynamic" Style="color: Red;" />
                        <asp:RegularExpressionValidator ID="regContactNumber" runat="server" ControlToValidate="txtContactNumber"
                            ValidationGroup="modal" Text="Only 10 digit valid contact number is valid." ValidationExpression="[0-9]{10}"
                            Style="color: Red;" Display="Dynamic"></asp:RegularExpressionValidator>
                        <asp:Button ID="btnRegister" ValidationGroup="modal" class="btnempregsubmit" runat="server"
                            Text="Save" OnClick="Register" CausesValidation="false" />
                        <br />
                        <asp:HyperLink ID="btnCancel" runat="server" Text="Cancel" CssClass="btnClosePopup">Close</asp:HyperLink>
                    </asp:Panel>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="grdSearchResult" />
                    <asp:AsyncPostBackTrigger ControlID="btnRegister" />
                </Triggers>
            </asp:UpdatePanel>

2 个答案:

答案 0 :(得分:1)

当你提到'一种替代方法是通过链接点击使用Onclick事件但是我不想回复打开Popupextender时,这有点令人困惑。 '如果你想要一个OnClick事件,你将不得不进行回发。以下是建议。

.....这部分是你的代码......

<asp:LinkButton ID="lnkFake" runat="server"></asp:LinkButton>
                    <cc1:ModalPopupExtender ID="mp1" BehaviorID="behaviorIDmp1" runat="server" PopupControlID="Panl1"
                        TargetControlID="lnkViewContact" CancelControlID="btnCancel" DropShadow="true" BackgroundCssClass="modalBackground">
                    </cc1:ModalPopupExtender>

....替换为......

<asp:LinkButton ID="lnkFake" runat="server"></asp:LinkButton>
                    <cc1:ModalPopupExtender ID="mp1" BehaviorID="behaviorIDmp1" runat="server" PopupControlID="Panl1"
                        TargetControlID="lnkFake" CancelControlID="btnCancel" DropShadow="true" BackgroundCssClass="modalBackground">
                    </cc1:ModalPopupExtender>

在OnClick事件代码后面,执行此操作以显示弹出窗口

mp1.Show()

答案 1 :(得分:0)

Gridview中的Linkbutton不能设置为Modalpopupextender的TargetcontrolID,因为在运行时链接按钮的ID会动态地改变。解决方法是使用LinkBut​​ton的Onclick事件,就像我的情况一样,如果modalpopupextender中有任何验证,那么验证服务器端的控件。