Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

500 points --- Retrieving value from Iframe

Hi, I am an ASP Programmer and now just started learning ASP.Net with Vb.Net.

I am trying to put the value of an iframe from WYSIWYG editor, to SQL database, but I am not able to retrieve value from Iframe. Can anyone tell me what is the way to retrieve the value from Iframe, as in ASP it was Request.form("field_name").

Please make suggestions ASAP.

Khurram.
0
khurram007
Asked:
khurram007
  • 3
  • 3
  • 2
  • +2
1 Solution
 
shovavnikCommented:
I'm not quite sure how you're trying to retrieve the value.

It is impossible, both with asp and asp.net to retrieve values directly from an iframe on the server-side.

One solution is to use javascript to update a textbox on the containing frame whenever the text is modified in the editor.  Then, when you post back, you can use the value from your textbox.  Just make sure your textbox is multiline, and invisible.
0
 
khurram007Author Commented:
I am not that good in Javascript... can you provide me a working sample?
0
 
fahimnxbCommented:
Dear khurram,

A working sample might be provided, please give us some of you source/html.

Regards,
Me
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
khurram007Author Commented:
Just provide me sample showing how to transfer iframe value to a hidden text field and then retrieving on other page.
0
 
zulu_11Commented:
U cannot get values from an IFRAME windows...it's not allowed..
If the framed site is not yours (from the same domain as the top domain), you can't know where user is going and what user is doing. This is built in security feature of the browser.

Zulu
0
 
khurram007Author Commented:
I am building the site myself. So no security issue should be there.

The question now is how to transfer iframe value to a hidden text field and then retrieving on other page??? and need a sample code doing that... Remember I am using Iframe for a WYSIWYG editor.

And one more question. I have WYSIWYG editors which use javascript and html text area. Can they work in Asp.net???
0
 
zulu_11Commented:
try this...
since you are making this site yourself...use javascript to write the value of the field you want in a cookie..and then from the other page where you want to read this value..again use javascript to read the cookie value..
and yes..javascript and textarea work in ASP.NET

here are some sites which can help u with this

http://www.quirksmode.org/js/cookies.html

http://www.tutorialized.com/forum/viewtopic.php?t=400

Zulu
0
 
jnhorstCommented:
What do you mean by getting the "value" from an <iframe>.  If you mean getting the URL of the page showing in the frame, first make the <iframe> a server control by doing this:

<iframe id="frmName" runat="server" src="http://www.someurl.com"></iframe>

This will cause ASP.NET to declare a variable to the HtmlGenericControl class for the iframe.  The variable will be whatever you put in the id="..." attribute.  Then get that value in code like this:

string frameURL = frmName.Attributes["src"]

You can then save that to a database.

John
0
 
jnhorstCommented:
Note, however, this will only get the *original* URL loaded when the page loaded.  I don't think it will get the current URL if the user has navigated elsewhere.

John
0
 
shovavnikCommented:
khurram, here's a rough-draft of a working example of what I meant.

ContainingPage.aspx:
<form runat="server" ...>
  <asp:TextBox runat="server" id="MyText" TextMode="Multiline" style="display:none;visibility:hidden;"></asp:TextBox>
  <iframe id="MyEditorFrame" src="MyEditor.aspx"></iframe>
</form>

Make sure to add a TextChanged event to your MyText control.  It will be called on post back when the editor in the iframe (below) is modified.

MyEditor.aspx:
<head>
<script>
  function updateText( obj )
  {
    var container = window.parent; // you can also use "top" if your container is the root frame
    var textbox = container.document.getElementById( 'MyText' );
    textbox.value = obj.value;
    // if the above line doesn't work, then try:
    // textbox.innerText = obj.innerText;
  }
</script>
<body>
<form runat="server" ...>
  <!-- all the html code for the editor -->
  <!-- on the textbox itself, which will be either an asp:TextBox with textmode set to multiline or a Textarea control
         (which are essentially identical), you need to have an onchange, or an onblur event: -->
  <textarea id="MyTextArea" onchange="updateText(this);"></textarea>
</form>
</body>

Note that this page does not need to post back ever.  Nor do you need a separate button to propogate the update to the parent frame.  It happens automatically when the user edits text in the editor.  If it works too slow (it shouldn't!) then respond to the onblur event instead of the onchange event.  The onblur event is only fired when the control loses focus, so it may be a bit less reliable, but will prevent it from being slow (which it should not be anyway).


Let me know if I can clarify on any part of this solution.
0
 
shovavnikCommented:
By the way, this is standard javascript, and does not in itself have any security issues (as far as I know).

The only thing you need to be careful of, regardless of the solution you implement, is that the users can put dangerous javascript in your textarea in your editor.  You'll need to either do validation, to make sure there's no <script> element in the user-entered code, or enable the safeguard in your web.config.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now