mohamed mohamed - 3 months ago 58
ASP.NET (C#) Question

how to access iframe textbox id in current page?

Friends I have a Parent Page(default.aspx) that includes an iframe page(iframe.aspx) containing textbox in the field. The parent page contains the "Save" button. Now i want to get the values of iframe page while submitting the parent page. How can i access the iframe pages fields in parent page submit?

iframe.aspx page,,,,
In Iframe page i have two textbox,,

<asp:textbox id="txtfromdate" runat="server"></asp:textbox>
<asp:textbox id="txttodate" runat="server"></asp:textbox>


default.aspx page

<iframe id="iframebody" runat="server" src="iframe.aspx" style="width:900px; height:600px"></iframe>

<asp:button id="submit" text="save" runat="server" />


frdz how to access iframe page id(txtfromdate, txtTodate) in parrent page(default.aspx) when i click on button??

Answer

Try this javascript on the button click.

HTML

<input type="hidden" id="txtHidData" runat="server" />

Javascript

var iframe = document.getElementById('iframebody');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var usernameTextBox = innerDoc.getElementById('txtfromdate');
document.getElementById ( "txtHidData" ).value = usernameTextBox.value;

C#

string valueInCodeBehind = txtHidData.Value;