在源页面中获取iframe ID [英] Get iframe id in source page
问题描述
我有两个页面,一个是主页面,另一个是常见页面。在主页面中,我还有两个小部件和包含iframe的小部件,其中包含公共页面的源代码。所有具有相同公共页面的小部件,当我点击iframe的按钮时,它会转到按钮点击事件后面的公共页面代码。在那里我想要iframe的id,其中iframe初始化了常用页面中的按钮点击。我可以得到它吗?请帮忙。
我的尝试:
主页:
< div>
< iframe id =widget1src =commonpage.aspx>< / iframe>
< / div>
< div>
< iframe id =widget2src =commonpage.aspx>< / iframe>
< / div>
常用页面:
< form runat =server>
< div>
< p>测试页< / p>
< asp:Button ID =Button1runat =serveronclick =Button1_ClickText =TestButton>< / asp:Button>
< div>
< form>
代码落后:
protected void Button1_Click(对象发件人,EventArgs e)
{
//这里我想要iframe ID。哪一个发起了事件
}
试试这个
在Common Page ASPX中:
编写一个javascript函数来获取Iframe ID并将其存储在隐藏字段中
function SetWidgetName(){
document .getElementById(' <%= hdnWidgetName.ID%>')。value = window .frameElement.id
}
< pre lang =ASP.NET> < asp:按钮 ID = Button1 OnClientClick = SetWidgetName(); runat = 服务器 OnClick = Button1_Click 文字 = TestButton > < / asp:按钮 >
< asp:HiddenField ID = hdnWidgetName runat = server / >
代码背后:
受保护 < span class =code-keyword> void Button1_Click( object sender,EventArgs e)
{
string widgetName = hdnWidgetName.Value; // 获取iframe ID
}
Hi,
I have two pages, one is main page and another one is a common page. In the main page i have two more widgets and the widgets containing iframe with source of common page. all widgets having the same common page, when i click a button of iframe its went to common page code behind button click event. There I want the id of iframe, in which iframe initialized the button click in the common page.how can i get it? please help.
What I have tried:
main page:
<div> <iframe id="widget1" src="commonpage.aspx"></iframe> </div> <div> <iframe id="widget2" src="commonpage.aspx"></iframe> </div>
common page:
<form runat="server"> <div> <p>Test page</p> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="TestButton"></asp:Button> <div> <form>
code behind:
protected void Button1_Click(object sender,EventArgs e) { // here i want the iframe id. which one initiated the event }
Try this
In Common Page ASPX:
Write a javascript function to get the Iframe ID and store it in a hidden field as
function SetWidgetName() { document.getElementById('<%= hdnWidgetName.ID%>').value = window.frameElement.id }
<asp:Button ID="Button1" OnClientClick="SetWidgetName();" runat="server" OnClick="Button1_Click" Text="TestButton"></asp:Button> <asp:HiddenField ID="hdnWidgetName" runat="server" />
Code behind:
protected void Button1_Click(object sender, EventArgs e) { string widgetName = hdnWidgetName.Value; // get the Iframe ID }
这篇关于在源页面中获取iframe ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!