Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
}
Posted
Updated 4-Aug-16 20:49pm
v2

1 solution

Try this

In Common Page ASPX:
Write a javascript function to get the Iframe ID and store it in a hidden field as

JavaScript
function SetWidgetName() {
           document.getElementById('<%= hdnWidgetName.ID%>').value = window.frameElement.id
     }


ASP.NET
<asp:Button ID="Button1"  OnClientClick="SetWidgetName();" runat="server" OnClick="Button1_Click" Text="TestButton"></asp:Button>
<asp:HiddenField ID="hdnWidgetName" runat="server"  />


Code behind:


C#
protected void Button1_Click(object sender, EventArgs e)
      {
          string widgetName = hdnWidgetName.Value; // get the Iframe ID
      }
 
Share this answer
 
Comments
Member 11125335 5-Aug-16 3:53am    
Thank very much friend. its working.
Karthik_Mahalingam 5-Aug-16 4:22am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900