Click here to Skip to main content
15,669,040 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 can i get it? please help.

What I have tried:

main page:
    <iframe id="widget1" src="commonpage.aspx"></iframe>

<iframe id="widget2" src="commonpage.aspx"></iframe>

common page:

<form  runat="server">
      <p>Test page</p>
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="TestButton"></asp:Button>

code behind:
protected void Button1_Click(object sender,EventArgs e)
           // here i want the iframe id. which one initiated the event
Updated 4-Aug-16 20:49pm

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

function SetWidgetName() {
           document.getElementById('<%= hdnWidgetName.ID%>').value =

<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
Share this answer
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