ASP.NET Update Panel问题,包含两个文件上载控件和Ajax Model Pop up事件

时间:2012-08-06 07:11:26

标签: asp.net asp.net-ajax

我在Asp.Net更新面板中遇到了一个大问题,即Update面板包含两个文件上传控件,一个用于Image updalod,第二个用于Document uplload,在此我有一个Ajax模型弹出事件用于输入Address细节到Grid。问题是在上传图像/文档后,如果我点击模型弹出链接它显示JavaScript错误“Microsoft JScript运行时错误:'myScriptpagename'未定义”。 任何人都可以解释如何在一个更新面板或多个面板中实现两个FileUploads和Ajax模型弹出窗口?

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="ServerClick" />
                <asp:PostBackTrigger ControlID="btnOKLogoUpload" />
                <asp:PostBackTrigger ControlID="btnOKDocumentUpload" />  
            </Triggers>
            <ContentTemplate>
        <div id="divCompanyInformation" style="width: 40%; float: left">
            <div class="sectionname">
                &nbsp &nbsp Company Information
            </div>
            <br />
            <div class="narrow" style="width: 85%; height: 90px; float: Left; padding-left: 50px">
                <div style="border: 1px #C1D6DB solid; width: 60%; height: 90px; float: left">
                    <asp:Image ID="imgCompanyLogo" runat="server" Width="100%" Height="90px" BorderStyle="Solid"
                        BorderWidth="1px" />
                </div>
                <div style="padding-top: 20px; width: 39%; height: 60px; float: left">
                    <input type="Button" runat="server" id="btnLogoUpload" value="Upload" style="width: 60px;
                        height: 22px" />
                    <br />
                    <asp:Button runat="server" ID="btnLogoDelete" Text="Delete" Style="width: 60px;"
                        OnClientClick="return btnLogoDelete_Click();" OnClick="btnLogoDelete_Click" />&nbsp;
                </div>
            </div>

        </div>

        <cc1:ModalPopupExtender runat="server" ID="LogoUploadPopup" BehaviorID="LogoUploadPopupBehavior"
    TargetControlID="btnLogoUpload" PopupControlID="pnlLogoUploadPopup" BackgroundCssClass="ModalBackground"
    DropShadow="false" PopupDragHandleControlID="LogoUploadPopupDragHandle" OkControlID="btnOKLogoUpload"
    CancelControlID="btnCancelLogoUpload" RepositionMode="RepositionOnWindowScroll">
</cc1:ModalPopupExtender>
<asp:Panel runat="server" CssClass="ModalDialog" ID="pnlLogoUploadPopup" Style="display: none;
    width: 440px; height: 170px">
    <div>
        <h1 id="H5" style="width: 100%; white-space: nowrap; margin-top: -1px" runat="server"
            class="popupHeader">
            &nbsp;Company Logo Upload</h1>
    </div>
    <div class="mainRoundedDiv" style="margin-top: 7px; margin-left: 17px; height: 85px;
        width: 400px">
        <div id="divLogoUpload" style="margin-left: 15px; margin-top: 15px;">
            <label>
                Select Logo:</label>
            <asp:TextBox ID="txtLogoUpload" CssClass="text" runat="server" Style="width: 0px;
                display: none;"></asp:TextBox>
            <asp:FileUpload ID="fileLogo" runat="server" />
        </div>
        <br clear="all" />
        <div class="buttonBox" style="float: left; width: 330px; margin-left: 145px !important;
            margin-left: 50px;">
            <asp:LinkButton CssClass="button" runat="server" Text="Ok" ID="btnOKLogoUpload" OnClientClick="return btnLogoUpload_Click();"
                OnClick="btnOKLogoUpload_Click"></asp:LinkButton>&nbsp; <a href="#" class="button"
                    id="btnCancelLogoUpload">Cancel</a><br />
        </div>
    </div>
    <br />
    <br />
    <div>
        <label style="width: 120px;">
            &nbsp;</label>
    </div>
</asp:Panel>

                <div style="margin: 5px 13px 20px 13px; width: 57%; float: right;">
                    <div class="Tabs">
                        <asp:LinkButton CssClass="active" runat="server" ID="btnAddressDetails" OnClientClick="return TabClicked('AddressDetails')"><span style="width:95px;">Adddress</span></asp:LinkButton>
                        <asp:LinkButton CssClass="deactive" runat="server" ID="btnContactsDetails" OnClientClick="return TabClicked('ContactsDetails')"><span style="width:95px;">Contacts</span></asp:LinkButton>
                        <asp:LinkButton CssClass="deactive" runat="server" 
                        <asp:LinkButton CssClass="deactive" runat="server" ID="btnAgreementsDetails" OnClientClick="return TabClicked('AgreementsDetails')"><span style="width:95px">Agreements</span></asp:LinkButton>
                    </div>

                    <div id="divCompanyDetailsTabs" style="width: 98%; height: 460px; margin-right: 12px; margin-top: 40px">                      
                        <div id="divAddressDetails" style="float: left; width: 100%; height: 95%; clear: none;
                            line-height: 25px;">
                            <div class="sectionname">
                                Address Information
                            </div>
                            <div style="width: 100%; position: relative; overflow: auto; height: 100%; border: 1px solid #C1D6DB;">
                                <div class="narrow" style="width: 875px;">
                                    <asp:GridView ID="grdAddressDetails" AutoGenerateColumns="False" runat="server" OnRowCreated="grid_OnRowCreated"
                                        OnRowDataBound="grdAddressDetails_RowDataBound">
                                        <HeaderStyle CssClass="GridHeader" />
                                        <AlternatingRowStyle CssClass="GridAlternateRow" BackColor="White" ForeColor="#284775" />
                                        <RowStyle BackColor="White" ForeColor="#284775" CssClass="GridRow" Height="25px" />
                                        <Columns>
                                            <asp:TemplateField HeaderStyle-Width="25px" ItemStyle-Width="25px" ItemStyle-HorizontalAlign="Center">
                                                <ItemTemplate>
                                                    <a href="#" id="lnkDelete" title="Delete Company" onclick="return DeleteAddress('<%# Eval("AddressId") %>')">
                                                        <%# (Eval("AddressId").ToString() != "1" ? "<img border='0' src='Images/delete.gif'>" : "")%></a>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Address Type" HeaderStyle-Width="90px" ItemStyle-Width="90px"
                                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" SortExpression="CompanyTypeText">
                                                <ItemTemplate>
                                                    <a href="#" title="Edit Company" onclick="return EditAddress('<%# Eval("AddressId") %>')">
                                                        <%# Eval("AddressTypeText")%>
                                                    </a>
                                                </ItemTemplate>
                                            </asp:TemplateField>                                            </Columns>
                                    </asp:GridView>
                                </div>
                            </div>
                        </div>
                        <div id="divContactsDetails" style="float: left; width: 100%; clear: none; line-height: 35px;">
                            <div class="sectionname" style="width: 300px; margin-top: -5px">
                                Company Contact Information
                            </div>
                            <div style="width: 100%; position: relative; overflow: auto; height: 430px; border: 1px solid #C1D6DB;">
                                <div class="narrow" runat="server" style="width: 930px;">
                                    <asp:GridView ID="grdContactsDetails" AutoGenerateColumns="False" runat="server"
                                        OnRowCreated="grid_OnRowCreated" OnRowDataBound="grdContactsDetails_RowDataBound">
                                        <HeaderStyle CssClass="GridHeader" />
                                        <AlternatingRowStyle CssClass="GridAlternateRow" BackColor="White" ForeColor="#284775" />
                                        <RowStyle BackColor="White" ForeColor="#284775" CssClass="GridRow" Height="25px" />
                                        <Columns>
                                            <asp:TemplateField HeaderStyle-Width="25px" ItemStyle-Width="25px" ItemStyle-HorizontalAlign="Center">
                                                <ItemTemplate>
                                                    <a href="#" id="lnkDelete" title="Delete Company" onclick="return DeleteContacts('<%# Eval("ContactId") %>')">
                                                        <%# (Eval("ContactId").ToString() != "1" ? "<img border='0' src='Images/delete.gif'>" : "")%></a>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Contact Type" HeaderStyle-Width="150px" ItemStyle-Width="150px"
                                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" SortExpression="CompanyTypeText">
                                                <ItemTemplate>
                                                    <a href="#" title="Edit Company" onclick="return EditContacts('<%# Eval("ContactId") %>', 0)">
                                                        <%# Eval("ContactTypeText")%>
                                                    </a>
                                                </ItemTemplate>
                                            </asp:TemplateField>                                            </Columns>
                                    </asp:GridView>
                                </div>
                            </div>
                        </div>                                                   
                        <div id="divAgreementsDetails" style="float: left; width: 100%; clear: none; line-height: 25px;">
                            <div class="narrow" style="width: 100%; text-align: left">
                                <label style="width: 65px">
                                    Documnets:</label>
                                <input type="Button" runat="server" id="btnDocumentUpload" value="Upload" style="width: 60px;" />
                            </div>
                            <div id="divAttachments" style="float: left; width: 100%; height: 410px; clear: none; line-height: 25px; margin-top: 20px; 
                                 border: 1px solid #C1D6DB; overflow: auto">
                                <div class="narrow" runat="server" style="width: 875px; height: 335px;">
                                    <asp:GridView ID="grdAttachments" AutoGenerateColumns="False" runat="server" Width="100%"
                                        OnRowCreated="grid_OnRowCreated">
                                        <HeaderStyle CssClass="GridHeader" />
                                        <AlternatingRowStyle CssClass="GridAlternateRow" BackColor="White" ForeColor="#284775" />
                                        <RowStyle BackColor="White" ForeColor="#284775" CssClass="GridRow" Height="25px" />
                                        <Columns>
                                            <asp:TemplateField HeaderStyle-Width="20px">
                                                <ItemStyle Width="20px" HorizontalAlign="Center" />
                                                <ItemTemplate>
                                                    <a href="#" id="lnkDelete" title="Delete Document" onclick="return  DeleteDocument('<%# Eval("AttachmentId") %>')">
                                                        <%# (Eval("Delete").ToString() != "1" ? "<img border='0' src='Images/delete.gif'>" : "")%></a>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Document Name" HeaderStyle-Width="340px" ItemStyle-Width="340px"
                                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="left" SortExpression="DocumentName">
                                                <ItemTemplate>
                                                    <asp:HyperLink ID="hlnkDocumentName" runat="server" NavigateUrl='<%# Eval("OriginalFileName", "javascript:openWindow(&#039;{0}&#039;);") %>'
                                                        Text='<%# Eval("DocumentName") %>'> </asp:HyperLink>
                                                    <%--#039 removes all "\"--%>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="Comments" HeaderText="Comments" HeaderStyle-Width="250px"
                                                HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Left">
                                            </asp:BoundField>
                                        </Columns>
                                    </asp:GridView>
                                </div>
                            </div>
                        </div>
                                                    <input id="hdnLogoFileName" type="hidden" runat="server" />
                        <input id="hdnDocument" type="hidden" runat="server" />
                        <input id="hdnDocumentFileName" type="hidden" runat="server" />
                                                    <input id="hdnCompanyLogoId" type="hidden" runat="server" />

                                                    <asp:Button ID="btnListAddress" runat="server" OnClick="btnListAddress_ServerClick" Style="display: none" />
                        <asp:Button ID="btnDeleteAddress" runat="server" OnClick="btnDeleteAddress_ServerClick" Style="display: none" />
                        <asp:Button ID="btnDeleteDocument" runat="server" OnClick="btnDeleteDocument_ServerClick" Style="display: none" />

                        <cc1:ModalPopupExtender runat="server" ID="DocumentUploadPopup" BehaviorID="DocumentUploadPopupBehavior"
                            TargetControlID="btnDocumentUpload" PopupControlID="pnlDocumentUploadPopup" BackgroundCssClass="ModalBackground"
                            DropShadow="false" PopupDragHandleControlID="DocumentUploadPopupDragHandle" OkControlID="btnOKDocumentUpload"
                            CancelControlID="btnCancelDocumentUpload" RepositionMode="RepositionOnWindowScroll">
                        </cc1:ModalPopupExtender>
                        <asp:Panel runat="server" CssClass="ModalDialog" ID="pnlDocumentUploadPopup" Style="display: none;
                            width: 470px; height: 220px">
                            <div>
                                <h1 id="H1" style="width: 100%; white-space: nowrap; margin-top: -1px" runat="server"
                                    class="popupHeader">
                                    &nbsp;Document Upload</h1>
                            </div>
                            <div class="mainRoundedDiv" style="margin-top: 7px; margin-left: 14px; height: 135px;
                                width: 440px">
                                <div id="divDocumentUpload" style="margin-left: 15px; margin-top: 15px;">
                                    <label>
                                        Select Document:</label>
                                    <asp:TextBox ID="txtDocumentUpload" CssClass="text" runat="server" Style="width: 0px;
                                        display: none;"></asp:TextBox>
                                    <asp:FileUpload ID="fileDocument" runat="server" />
                                    <br />
                                    <br />
                                    <label>
                                        Comments:</label>
                                    <textarea id="txtComments" rows="2" cols="27" runat="server" style="overflow: auto" />
                                    <br />
                                </div>
                                <br clear="all" />
                                <div class="buttonBox" style="float: left; width: 330px; margin-left: 115px !important;
                                    margin-left: 50px;">
                                    <asp:LinkButton CssClass="button" runat="server" Text="Ok" ID="btnOKDocumentUpload"
                                        OnClientClick="return btnDocumentUpload_Click();" OnClick="btnOKDocumentUpload_Click"></asp:LinkButton>&nbsp;
                                    <a href="#" class="button" id="btnCancelDocumentUpload">Cancel</a><br />
                                </div>
                            </div>
                            <br />
                            <br />
                            <div>
                                <label style="width: 120px;">
                                    &nbsp;</label>
                            </div>
                        </asp:Panel>
                    </div>
                </div>
</ContentTemplate>

Ajax模型弹出窗口:

function EditContacts(contactId){

        var companyId = $get('hdnCompanyId').value;

        var url = "AddContacts.aspx?ContactId=" + contactId + "&EntityId=" + companyId + "&EntityType=COMPANY";
        Alticore.Framework.openModalFrame('divEditContacts', url, { 'callback': contactPopupClosed, 'draggable': true, 'title': "Contacts ", 'width': '600px', 'height': '350px' });
    }

    function contactPopupClosed(response) // This method is called when the Popup is closed
    {
        try {
            if (response.IsOk) {
                $get('btnListContacts').click();
                activeTabId = "ContactsDetails";
                //TabClicked('ContactsDetails');
            }
        }
        catch (e) {
            alert(e.message);
        }
    }

0 个答案:

没有答案