locked
改變ModalPopupExtender 內 iframe的src RRS feed

  • 問題

  • 如何可以改變iframe的src

    以下的 javascript alert顯示 src 已經改變了

    但顯示出來的iframe , 又沒有變化.

    請大家幫手.

    Thanks

     <script type="text/javascript">

         function download(val) {
            
             var iframe = document.getElementsByName("DocFrame");

             alert(iframe.src);
             iframe.src="http://aa.htm" ;
                    
         }
     </script>

       

      <asp:TemplateField HeaderText="文本">
                            <HeaderTemplate>                       
                               
                            </HeaderTemplate>
                            <ItemTemplate>                         
                                <asp:ImageButton ID="btnDocLink" runat="server"  OnClientClick="download('http://www.abc.com')" ImageUrl="~/Images/zoom.png" />
                                <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"  PopupControlID="DocPanel" TargetControlID="btnDocLink" >
                                </cc1:ModalPopupExtender>
                            </ItemTemplate>
                            <HeaderStyle   />
                            <ItemStyle HorizontalAlign="Center" Width="20px"></ItemStyle>
       </asp:TemplateField>



    <asp:Panel ID="DocPanel" runat="server" CssClass="modalBox" Style="display: none;" Width="800px" Height="500">
        <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
       
        <iframe id="DocFrame" src="">
        </iframe>
     
        <div class="footer">
            <asp:LinkButton ID="btnSave" originalAttribute="src" originalPath="">
        </iframe>
     
        <div class="footer">
            <asp:LinkButton ID="btnSave" runat="server" Text="Save" OnClick="BtnSave_Click" CausesValidation="true" />
            <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
        </div>
    </asp:Panel>
       

    2009年3月10日 上午 11:09

解答

  • 你好

    Nice to heard that It seems to work.

    你的grid VIEW 中有沒有一個 FIELD 是用來STORE Eval("SeqId") 的?
    如果有或者你可以用返這個 有Eval("SeqId") 的 CONTROL 來RETRIEVE 返這個 VALUE
    E.G.

    Dim lbl As Label = e.Row.FindControl("lbl_SeqId")
    btn.OnClientClick = "window.open('PubsOrderDetails.aspx?OrderId=" & lbl.Text & "','','scrollbars=yes,resizable=yes, width=350, height=550');"

    Hope this can get around that problem
    Chi
    • 已標示為解答 Lam0706 2009年3月17日 上午 04:18
    2009年3月16日 下午 12:40

所有回覆

  •  有沒有人可以幫下我

    急用的

    請幫手解決.

    謝謝大家.

    或者有沒有其他方法 ?
    2009年3月12日 上午 03:16
  • HI 你好

    我試過用COPY AND PASTE 你D CODE 去我個PAGE 度
    但我REMOVE 了你的 ASPTEMPLATE FIELD 去做我個TESTING

    maybe u can try to use

    我改了你的一句 JAVASCRIPT 不知度這可不可以SOLVE 你的問題

    <script type="text/javascript">

        function download(val) {

            var iframe = document.getElementById("DocFrame");
    // var iframe = document.getElementsByName("DocFrame"); <--你的VERSION

            alert(iframe.src);
            iframe.src = "http://www.yahoo.com";

        }
     </script>
    <asp:Button ID="btn_Example" runat="server" Text="Example" />
     
      

      

                           
                                <asp:ImageButton ID="btnDocLink" runat="server"  OnClientClick="download('http://www.abc.com')" ImageUrl="~/Images/zoom.png" />
                                <AjaxControlToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"  PopupControlID="DocPanel" TargetControlID="btnDocLink" >
                                </AjaxControlToolkit:ModalPopupExtender>
     


    <asp:Panel ID="DocPanel" runat="server" CssClass="modalBox" Style="display: none;" Width="800px" Height="500">
        <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
      <iframe id="DocFrame" src="">
        </iframe>
      
     
        <div class="footer">
            <asp:LinkButton ID="btnSave" originalAttribute="src" originalPath=""></iframe><div class="footer">

            <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
        </div>
    </asp:Panel>


    Hope this can help

    Chi
    • 已提議為解答 KeFang Chen 2009年3月12日 上午 05:37
    2009年3月12日 上午 04:42
  • 楼主,你好

    我认为上面的答案应该能解决你的问题,如果你的问题仍然存在,请提供信息。
    否则请你标记上面的回答为answer,谢谢。

    Microsoft Online Community Support
    2009年3月12日 上午 05:39
  •         var iframe = document.getElementById("DocFrame");
    // var iframe = document.getElementsByName("DocFrame"); <--你的VERSION

                   iframe.src=http://www.yahoo.com;



    getElementById

    getElementsByName
    一樣

    其實getElementsByName 用
    alert(iframe.src); 發現src 是改變了

    但顯示ModalPopupExtender的PANEL中的IFARME時, 就沒有更新,

    不知道是否是執行次序問題.


    還有, 我想在ModalPopupExtender 加入Onload , 把Eval("ID") 的值傳入Onload中,

    例如 onLoad="download( <% Eval("ID") %>)"
    應該如何編寫 ?

    cc1:ModalPopupExtender ID="ModalPopupExtender1"   onLoad="download( <% Eval("ID") %>)"
    runat="server"  PopupControlID="DocPanel" TargetControlID="btnDocLink" >

    2009年3月12日 下午 03:02
  • 你好

    請問你有沒有試過用 上面的CODE SAMPLE 有沒有解決到你的問題, 因為我試過是可以改善 IFRAME 入面的內容的.
    如果解決唔到你的問題或者你可以 POST 你的 CODE 上來 .ASPX & .VB 讓我們可以更了解你的問題

    如果你想使用 ONLOAD 你可以CREATE 一個 EVENT HANDLER
    之後放返你的 <% Eval("ID") %> 入去
    E.G.

      Protected Sub ModalPopupExtender1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ModalPopupExtender1.Load
    E.G. ASSIGN <% Eval("ID") %>  去一個LABEL 入面
    之後係 LABEL RETRIVE 返出來 (我不太了解怎樣用<% Eval("ID") %>  的 SORRY)

    DIM id as string = label1.text
     DOWNLOAD(id)
    如果你的DOWNLOAD METHOD 是會之前的問題一樣 (係javascript)
    你可以試試用幾下的CODE 來CALL JAVASCRIPT

    Page.ClientScript.RegisterStartupScript(Me.GetType, "Key", "download('" & id & "');", True)
        End Sub


    Hope this can help

    Chi
    2009年3月12日 下午 09:35
  • 我改用另一方法.
    在GridView 中有一個 ImageButton, ID="btnSetDocLink"
    OnClick 就執行 "SetIframeLink" 並把SeqId 傳入.     ( 或者用OnClientClick )
    "SetIframeLink" 作用是把 iframe 的 src 動態改變.   但沒有反應.

    <script type="text/javascript">

        function download(val) {

            //var iframe = document.getElementsById("DocFrame");
            var iframe = document.getElementsByName("DocFrame");
           //alert(iframe.src);        
            iframe.src=val;
        }
    </script>

                                      <asp:TemplateField HeaderText="文本">
                                               <HeaderTemplate>
                                                </HeaderTemplate>
                                                    <ItemTemplate>                                                                                                             
                                                  <asp:ImageButton ID="btnSetDocLink" runat="server"  ImageUrl="~/Images/doc.gif" OnClientClick="download('http://www.yahoo.com')"  OnClick="SetIframeLink"  CommandName="SetDocLink" CommandArgument='<%# Eval("SeqId_ch") %>'/>
                                                                                                                    
                                                 </ItemTemplate>
                                                  

                                      </asp:TemplateField>
            

    <asp:Panel ID="DocPanel" runat="server" CssClass="modalPopup" Style="display: none;"
        Width="900px" Height="600">
        <div class="footer" style="text-align: left">
        </div>
        <div class="footer" style="text-align: right">
            <asp:ImageButton ID="btnClose" runat="server" AlternateText="Close" ImageUrl="~/Images/CloseX.png"
                CausesValidation="false" Width="38px" Height="38px" />
        </div>
        <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
        <iframe id="DocFrame" width="900px" height="550" src=''></iframe>
    </asp:Panel>

    <asp:ImageButton ID="btnTMP" runat="server" ImageUrl="~/Images/doc.gif" />   
    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="DocPanel"
        BackgroundCssClass="modalBackground" TargetControlID="btnTMP" CancelControlID="btnClose">
    </cc1:ModalPopupExtender>







           Sub SetIframeLink(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)

            Dim arg As String = sender.CommandArgument
            Try

                Dim JsString As String = String.Format("document.getElementsByName('DocFrame').src='http://abc.com?id={0}'", CType(arg, String))

                ScriptManager.RegisterStartupScript(Me, Me.GetType, "iframeLink", JsString.ToString(), True)

                Me.ModalPopupExtender1.Show()

            Catch ex As Exception
                Trace.Warn(ex.ToString)
            End Try

    2009年3月13日 上午 09:21
  • 你好
    你的 ModalPopupExtender1 是不是在 grid view 入面 as well?
    Chi
    2009年3月13日 上午 09:58
  • 之前是在Gridview 入面, 之後覺得在外面都可以, 就放在外面

    剛試多一個方法, 但都不成,


        Sub SetIframeLink(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)

            Dim arg As String = sender.CommandArgument
            Try

                Dim DocFrame As HtmlControl = CType(Me.FindControl("DocPanel").FindControl("DocFrame"), HtmlControl)

                DocFrame.Attributes("src") = "http://www.live.com"

                Me.ModalPopupExtender1.Show()

            Catch ex As Exception
                Trace.Warn(ex.ToString)
            End Try
        End Sub

    2009年3月13日 上午 10:53
  • 你好

    你的iframe 都在 gridview 出面嗎
    ?
    如果是的話
    應該可以試用
    Sub SetIframeLink(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)

    Page.ClientScript.RegisterStartupScript(Me.GetType, "Key", "download('" & id & "');", True)

    end sub

    去 run javascript 去 load 這個url 的
    這樣你便不用

    找個iframe control 了

    <script type="text/javascript">

        function download(val) {

            var iframe = document.getElementById("DocFrame");
    // var iframe = document.getElementsByName("DocFrame"); <--你的VERSION

            alert(iframe.src);
            iframe.src = val;

        }
     </script>


    good luck

    Chi
    2009年3月13日 上午 11:24
  •  

    Page.ClientScript.RegisterStartupScript 沒有反應.

    還是不成


    現在多了一個問題

    當ModalPopupExtender1 .show 後, 自己在 gridview 加入的style 不見了. 例如我在 PagerTemplate 加上的文字和  css 消失了.,

    請問為甚麼會這樣的 ?


    Code如下


    Protected Sub gdvLawList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvLawList.RowDataBound

            If e.Row.RowType = DataControlRowType.Pager Then

                Dim pagerCell As TableCell
                pagerCell = CType(e.Row.Controls(0), TableCell)
                'pagerCell.Controls.Clear()
                Dim txt As String
                Dim txtGoPage As String

               txtGoPage = "Page No: "

                txt = "<font size='2pt'>" & txtGoPage & "&nbsp;</font><span class=i>"
                pagerCell.Controls.AddAt(0, New LiteralControl(txt))

                pagerCell.Controls.AddAt(pagerCell.Controls.Count, New LiteralControl("</span>"))

    2009年3月13日 下午 12:02
  • 你好

    我想你試試
    create 一個新的 aspx page

    之後
    paste 下面的code 去試試
    個function work 唔work 先

    這樣我可detemine 係d code 既問題
    or the way construct 個page 既問題



    <script type="text/javascript">

        function download(val) {

            var iframe = document.getElementById("DocFrame");
    // var iframe = document.getElementsByName("DocFrame"); <--你的VERSION

            alert(iframe.src);
            iframe.src = val;

        }
     </script>
    <asp:Button ID="btn_Example" runat="server" Text="Example" />
     
     

     

                          
                                <asp:ImageButton ID="btnDocLink" runat="server"  OnClientClick="download('http://www.abc.com')" ImageUrl="~/Images/zoom.png" />
                                <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"  PopupControlID="DocPanel" TargetControlID="btnDocLink" >
                                </ajaxToolkit:ModalPopupExtender>
     


    <asp:Panel ID="DocPanel" runat="server" CssClass="modalBox" Style="display: none;" Width="800px" Height="500">
        <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
      <iframe id="DocFrame" src="">
        </iframe>
     
     
        <div class="footer">
            <asp:LinkButton ID="btnSave" originalAttribute="src" originalPath=""></iframe><div class="footer">

            <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
       
    </asp:Panel>
    </div>



    Chi
    2009年3月13日 下午 12:48
  • 先謝謝你, 我要星期一回到公司才可以繼續, 但這個問題真是煩了我很久, 謝謝你的幫忙.

    但你知不知道我上一個post 提到當ModalPopupExtender1 .show 後, 自己在 gridview 加入的style 不見了. 例如我在 PagerTemplate 加上的文字和  css 消失了.,
    2009年3月13日 下午 03:47
  • 按你的Code , 沒有問題, iframe可以顯示內容, 

    但去到我的Code, 就沒有反應了.  


     

    2009年3月16日 上午 01:38
  • 我的Code 

    <table align="left" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td>
                <div class="grid">
                    <div class="rounded">
                        <div class="top-outer">
                            <div class="top-inner" style="width: 970px">
                                <div class="top">
                                </div>
                            </div>
                        </div>
                        <div class="mid-outer">
                            <div class="mid-inner" style="width: 970px">
                                <div class="mid">
                                    <asp:UpdatePanel ID="updatePanel" runat="server">
                                        <ContentTemplate>
                                           
                     
                                    <br />
                                            <asp:Panel ID="pHeader" runat="server" CssClass="cpHeader">
                                                <asp:Label ID="lblText" runat="server" Text="sEARCH" />
                                            </asp:Panel>
                                            <asp:Panel ID="pBody" runat="server" CssClass="cpBody">
                                            

                                            </asp:Panel>
                                   
                                                      </ContentTemplate>
                                    </asp:UpdatePanel>
                                                <br />
                                </div>
                            </div>
                            <div class="bottom-outer">
                                <div class="bottom-inner" style="width: 970px">
                                    <div class="bottom">
                                    </div>
                                </div>
                            </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="grid">
                    <div class="rounded">
                        <div class="top-outer">
                            <div class="top-inner" style="width: 970px">
                                <div class="top">
                                    <p>
                                    &nbsp;</div>
                            </div>
                        </div>
                        <div class="mid-outer">
                            <div class="mid-inner" style="width: 970px">
                                <div class="mid">
                                    <asp:Panel ID="pnlTools" runat="server"  Visible="false" >
                                    &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
                                    <asp:ImageButton ID="btnAdd" runat="server" PostBackUrl="~/Add.aspX"
                                        ToolTip="新 增" ImageUrl="~/Images/document_add.png" />
                                    <asp:ImageButton ID="btnDel" runat="server" ToolTip="刪 除" ImageUrl="~/Images/document_delete.png" />
                                    </asp:Panel>                               
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                        <ContentTemplate>
                                       
                                                            <div id="dlg" class="panel" style="width:963px">
                            <div class="header" style="cursor:default">
                                <div class="outer">
                                    <div class="inner">
                                        <div class="content">
                                            <h2>Export to Excel</h2>      
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="body">
                                <div class="outer">
                                    <div class="inner">
                                        <div class="content">
                                            <asp:GridView ID="gdvList" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                                ForeColor="Black" CssClass="datatable" CellPadding="0" BorderWidth="0px" GridLines="None"
                                                Width="950px" Font-Size="10pt" PageSize="10" AllowSorting="False">
                                                <Columns>
                                                    <asp:TemplateField HeaderText="編輯" Visible="false">
                                                        <HeaderTemplate>
                                                        </HeaderTemplate>
                                                        <ItemTemplate>
                                                            <asp:ImageButton runat="server" ImageUrl="~/Images/document_edit.png" PostBackUrl='<%# "AddLaw.aspx?Action=Edit&SeqId="& SwitchColumnLang(DataBinder.Eval(Container.DataItem, "SeqId_ch"), DataBinder.Eval(Container.DataItem, "SeqId_pt")) %>' />
                                                        </ItemTemplate>
                                                        <ItemStyle HorizontalAlign="Center" Width="15px"></ItemStyle>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Roles" Visible="false">
                                                        <HeaderTemplate>
                                                            <asp:CheckBox ID="chkAll" onclick="javascript:SelectAllCheckboxesSpecific(this);"
                                                                runat="server" />
                                                        </HeaderTemplate>
                                                        <ItemTemplate>
                                       
                                                            <asp:CheckBox onclick="javascript:HighlightRow(this);" ID="ChkSelection" runat="server" />
                                                        </ItemTemplate>
                                                        <HeaderStyle />
                                                        <ItemStyle HorizontalAlign="Center" Width="20px"></ItemStyle>
                                                    </asp:TemplateField>
                                                   
                                                   
                                                 
                                                    <asp:TemplateField HeaderText="Doc">
                                                        <HeaderTemplate>
                                                        </HeaderTemplate>
                                                        <ItemTemplate>                                                                                                            
                                                                 <asp:ImageButton ID="btnSetIframeLink" runat="server"  ImageUrl="~/Images/doc.gif" OnClick="SetIframeLink"  CommandName="SetIframeLink" CommandArgument='<%# Eval("SeqId_ch") %>'/>
                                                                 <asp:ImageButton ID="btnOpenDocLink" runat="server"  ImageUrl="~/Images/doc.gif" OnClick="OpenDocLink"  CommandName="OpenDocLink" CommandArgument='<%# Eval("SeqId_ch") %>'/>                                                                                                                
                                                       
                                                        </ItemTemplate>
                                                        <HeaderStyle />
                                                        <ItemStyle HorizontalAlign="Center" Width="20px"></ItemStyle>
                                                    </asp:TemplateField>
                                                </Columns>
                                                <FooterStyle BackColor="#CCCC99" />
                                                <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Center" />
                                                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                                                <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" Height="20px" />
                                                <PagerSettings Mode="Numeric" />
                                                <RowStyle VerticalAlign="Top" CssClass="row" Height="50pt" />
                                 
                                            </asp:GridView>
                                           
                                                       </div>
                                    </div>
                                </div>
                            </div>               
                            <div class="footer">
                                <div class="outer">
                                    <div class="inner">
                                        <div class="content"></div>
                                    </div>
                                </div>
                            </div>     
                        </div>
                                           
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                   
                                   
                                   
                                </div>
                            </div>
                        </div>
                        <div class="bottom-outer">
                            <div class="bottom-inner" style="width: 970px">
                                <div class="bottom">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
    </table>
      
       
       
       
    <asp:Panel ID="DocPanel" runat="server" Style="display: none;"
        Width="900px" Height="600">
        <div class="footer" style="text-align: left">
        </div>
        <div class="footer" style="text-align: right">       
       
            <asp:ImageButton ID="btnClose" runat="server" AlternateText="Close" ImageUrl="~/Images/CloseX.png"
                CausesValidation="false" Width="38px" Height="38px" />
        </div>
        <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
        <iframe id="DocFrame" width="900px" height="550" src=""></iframe>
       
    </asp:Panel>

      
    <asp:ImageButton ID="btnTMP" runat="server" ImageUrl="~/Images/doc.gif"   OnClientClick="download('http://www.abc.com')" />   

    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="DocPanel"
        BackgroundCssClass="modalBackground" TargetControlID="btnTMP"  CancelControlID="btnClose">
    </cc1:ModalPopupExtender>

    • 已編輯 Lam0706 2009年3月25日 上午 04:36
    2009年3月16日 上午 01:49
  • 你好

    不好意思我想知道你的MODALPOPUP 是顯示唔到任何東西?
    還是只係 個IFRAME RELOAD 唔到你PASS 入去的URL?

    你另一個POST 問到LIST <OF STRING>和 STRING()
    所以在這個POST 入面回了你
    你可以看看 能不能幫到你
    GOOD LUCK


    Chi
    2009年3月16日 上午 06:39
  • IFrame 不能 Reload  傳入的URL


    但奇怪, 我用這個方法都不成.

      ScriptManager.RegisterStartupScript(Me.UpdatePanel1, Me.GetType, "key", "download('http://www.abc.com')", True)

    沒有反應

    2009年3月16日 上午 08:33
  • 請問

    我改用之前的方法, 好像可以.



            Select Case e.Row.RowType

                Case DataControlRowType.DataRow
                    Dim btn As ImageButton = e.Row.FindControl("btnDocLink")
                    btn.OnClientClick = "window.open('PubsOrderDetails.aspx?OrderId=" & Eval("SeqId") & "','','scrollbars=yes,resizable=yes, width=350, height=550');"
            End Select


    但出現

    Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

    2009年3月16日 上午 08:47
  • 你好

    Nice to heard that It seems to work.

    你的grid VIEW 中有沒有一個 FIELD 是用來STORE Eval("SeqId") 的?
    如果有或者你可以用返這個 有Eval("SeqId") 的 CONTROL 來RETRIEVE 返這個 VALUE
    E.G.

    Dim lbl As Label = e.Row.FindControl("lbl_SeqId")
    btn.OnClientClick = "window.open('PubsOrderDetails.aspx?OrderId=" & lbl.Text & "','','scrollbars=yes,resizable=yes, width=350, height=550');"

    Hope this can get around that problem
    Chi
    • 已標示為解答 Lam0706 2009年3月17日 上午 04:18
    2009年3月16日 下午 12:40