Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

500 points --- Retrieving value from Iframe

Posted on 2004-09-15
11
Medium Priority
?
344 Views
Last Modified: 2013-12-16
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
Comment
Question by:khurram007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 8

Expert Comment

by:shovavnik
ID: 12062088
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
 
LVL 2

Author Comment

by:khurram007
ID: 12062571
I am not that good in Javascript... can you provide me a working sample?
0
 
LVL 5

Expert Comment

by:fahimnxb
ID: 12063078
Dear khurram,

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

Regards,
Me
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 2

Author Comment

by:khurram007
ID: 12063101
Just provide me sample showing how to transfer iframe value to a hidden text field and then retrieving on other page.
0
 
LVL 6

Expert Comment

by:zulu_11
ID: 12063239
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
 
LVL 2

Author Comment

by:khurram007
ID: 12063256
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
 
LVL 6

Expert Comment

by:zulu_11
ID: 12063360
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
 
LVL 10

Expert Comment

by:jnhorst
ID: 12067374
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
 
LVL 10

Expert Comment

by:jnhorst
ID: 12067407
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
 
LVL 8

Accepted Solution

by:
shovavnik earned 2000 total points
ID: 12084253
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
 
LVL 8

Expert Comment

by:shovavnik
ID: 12084286
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question