在用户控件和ASPX页面之间传递值

时间:2013-04-26 08:23:02

标签: c# asp.net

我想传递所选索引的值 在列表框(这是一个html文件名)中,作为iframe的src。

<iframe id="iframeID" 
        frameborder="0" 
        width="100%" 
        height="300px" 
        runat="server">
</iframe>

使用Javascript:

var x = document.getElementById('<%=ListBox1.ClientID %>');
var val = x.options[x.selectedIndex].value;            
document.getElementById("iframeID").src =  val; 

有人可以告诉我它有什么问题吗?感谢。

2 个答案:

答案 0 :(得分:1)

我注意到你在iframe上有runat="server",所以这次调用

document.getElementById("iframeID").src =  val;

也必须如下:

document.getElementById('<%=iframeID.ClientID %>').src =  val;

或从iframe中删除runat="server"

答案 1 :(得分:0)

可能:

var val = x.options[x.selectedIndex].text;