有一母板页MasterPage.master,网页a.aspx继承该母板页,现a.aspx中还有一iframe 。
我要提的问题是:
a.aspx页中要根据网页上的某个下拉框改变iframe中的src。<td><iframe name="Preview" id="Preview" src="http://community.csdn.net/" width="99%" height="300" marginwidth="20px" marginheight="20px" border="0" frameborder="0" scrolling="both"></iframe></td>现在的问题是:在前台js里倒是可以访问得到iframe,改变它的src并reload,但无效;
后台cs代码里通过string mScript = "<script>alert(1);alert(document.all.Preview);</script>";
        Response.Write(mScript);提示 document.all.Preview 为  “undefine”。
请问大家知道原因么,或有什么好的解决方法(改变iframe的src......)?
=======================
代码:
前台---
function RefreshExample(){
                    var control = document.getElementById("<%=hfExampleSou.ClientID%>");//定义了一个hiddenfield,用于后台换地址
            if (control.value != ""){
            {
                document.all.Preview.src = control.value;
                document.all.Preview.location.reload();
            }
            return true;
        }
后台----
if (hfExampleSou.Value.Equals("http://community.csdn.net/"))
            hfExampleSou.Value = "http://club.cat898.com/newbbs/list.asp?boardid=15";//
        hfExampleSou.Value = "http://community.csdn.net/";=====================
在iframe中只显示http://community.csdn.net/

解决方案 »

  1.   

    使用"Session"判断,反正就是一个判断值 看你的了!不同的的"Session"连接不同
    if (Session["UserID"] != null)
            {
                Iframe1.Attributes.Add("src", "landing.aspx");
            }
            else
            {
                Iframe1.Attributes.Add("src", "Default2.aspx");
            }
    另外iframe这样使用
    <iframe id="Iframe1" runat="server" frameborder="0" scrolling="no"  style="width: 180px; height: 140px">
    </iframe>
    在iframe中只显示http://community.csdn.net/ 这样的东西是使用的url混淆器,和iframe无关系
      

  2.   

    document.getElementById("Preview").src = control.value+"?temp="+Math.random();
      

  3.   

     Response.Write(mScript);的时候页面还没加载用 Page.ClientScript.RegisterStartupScript