日期:2014-05-17  浏览次数:20436 次

求助,动态设置iframe的src,不显示
aspx页面代码
C# code

<iframe id="Reply" width="100%" runat="server" scrolling="yes" src="<%=GetSrc() %>" ></iframe>


cs文件代码
C# code

    protected void ShowReply(object sender, EventArgs e)
    {
        //Panel1.Attributes.Add("style", "display:none");
        string url = "ShowEmailDetails.aspx?ID=" +_id ;
        Reply.Attributes.Add("src", url);

    }


我想单击按钮时设置iframe的src属性,但是iframe中的网页并没有显示,求高人指教

------解决方案--------------------
HTML code
        <iframe id="Reply" width="100%" runat="server" scrolling="yes" ></iframe>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

------解决方案--------------------
照你的写的代码,你可以拷贝测试,你看看每次的url变了吗?


C# code
<%@ Page Language="C#"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  private String _id = "";

  protected void ShowReply(object sender, EventArgs e)
  {
    _id = Guid.NewGuid().ToString();
    string url = "ShowEmailDetails.aspx?ID=" + _id;
    Reply.Attributes.Add("src", url);
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      Reply.Attributes.Add("src", "ShowEmailDetails.aspx");
    }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title></title>
</head>
<body>
  <form runat="server" id="form1">
  <iframe id="Reply" width="100%" runat="server" scrolling="yes"></iframe>
  <asp:Button ID="Button1" runat="server" onclick="ShowReply" Text="改变" />
  </form>
</body>
</html>

------解决方案--------------------
本来javascript可以轻松解决的问题,非要回发到后台,由asp.net来折腾
------解决方案--------------------
window.mainFrm.location = urlStr; //兼容IE FF