Solved

JavaScript Parent Document Get Element in asp.net's iframe

Posted on 2009-07-07
12
2,562 Views
Last Modified: 2012-05-07
I really shame on for this question but i could not understand why this is not working

when i delete the  :     scr += "parent.document.getElementById('Image1A').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
line ,it is working perfectly for A1 element when i use this code in an other page working again the only difference is i use this code in a master page's content page 's iframe
and this code is working on iframe and controlling an item from content's page inside master page
i think the problem is master page for only the finding images with javascript but why?
Dim item As New FileAsyncronUploader
        res = item.yukle(FileUpload1)
        Dim scr = "<script>"
        scr += "parent.document.getElementById('Image1A').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
        scr += "parent.document.getElementById('A1').style.visibility  = 'visible';"
        scr += "</script>"
        Response.Write(scr)

Open in new window

0
Comment
Question by:CahitEy
[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
  • 7
  • 5
12 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24801580
what is the error?

Server or client side?

What does the javascript look like in the view-source?
0
 
LVL 1

Author Comment

by:CahitEy
ID: 24802180
when i delete this line :
  scr += "parent.document.getElementById('Image1A').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
     
there is no problem or when i add this line :
  scr += "alert(' res ');"

there is no problem again

when i copy whole the page without any changing into a normal page instead of masterpage's content there is no problem again       the problem is js could not find the image1a when i use this code inside a master page i think master page changing the id's of element in html side because the problem is couldnot finding server side element on master page how could this resolve ?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24802415
Sooo, please use view-source and see what it is called.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:CahitEy
ID: 24802441
but there must be a standart for this i am creating objects also dynamically but asp.net is changing id's in masterpage and it will not work on multiple uploads
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24802642
Yes

   scr += "parent.document.getElementById('<%= Image1A.ClientID %>').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
  scr += "parent.document.getElementById('<%= A1.ClientID %>').style.visibility  = 'visible';"
     

refer this for a nicer looking solution

http://blog.jagregory.com/2006/04/12/how-to-use-clientids-in-javascript-without-the-ugliness/
0
 
LVL 1

Author Comment

by:CahitEy
ID: 24802707
but the problem is image1a in not on this page


  scr += "parent.document.getElementById('<%= Image1A.ClientID %>').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
 scr += "parent.document.getElementById('<%= A1.ClientID %>').style.visibility  = 'visible';"

this code workin in iframe so image1a will not be a known type on this code's page
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24802791
You are making your life complicated...

try this in the parent

<script>
function getObjectByClientId(id) {
  var tags = document.getElementsByTagName('*');
  for (var i=0, n=tags.length;i<n;i++) {
    if (tags[i].id.indexOf("_"+id)!=-1) {
      return tags[i];
    }
  }
}
</script>
 
and have
 
scr += "parent.getObjectByClientId('Image1a').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
scr += "parent.getObjectByClientId('A1').style.visibility  = 'visible';"
 
or save the client ids in variables in the parent:
var image1a = '<%= Image1A.ClientID %>'
var div1a = '<%= A1.ClientID %>'
 
 
scr += "parent.document.getElementById(parent.image1a).src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
scr += "parent.document.getElementById(parent.div1a).style.visibility  = 'visible';"

Open in new window

0
 
LVL 1

Author Comment

by:CahitEy
ID: 24802848
That seems like an answer but i could not understand this :

<script>
function getObjectByClientId(id) {
  var tags = document.getElementsByTagName('*');
  for (var i=0, n=tags.length;i<n;i++) {
    if (tags[i].id.indexOf("_"+id)!=-1) {
      return tags[i];
    }
  }
}
</script>


this function is returning tag of parent page's called id's tag in parant page but not changing the id to Image1a and this code is working in iframe so there won't be a connection beetwen items


scr += "parent.getObjectByClientId('Image1a').src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
scr += "parent.getObjectByClientId('A1').style.visibility  = 'visible';"
 
but i will try this 2 hours later this

var image1a = '<%= Image1A.ClientID %>'
var div1a = '<%= A1.ClientID %>'
 
 
scr += "parent.document.getElementById(parent.image1a).src = 'http://files.xxx.com/image.aspx?img=" + res + "&w=250&h=250';"
scr += "parent.document.getElementById(parent.div1a).style.visibility  = 'visible';"

this could be answer but i am not sure in asp.net  '<%= A1.ClientID %>' this will work because <% is classical asp tag.

thanks i will tell the result i increase the point to 150 for this attention
0
 
LVL 1

Author Comment

by:CahitEy
ID: 24802937
in parent document if i use
response.write("<script>var image1a = '" & Image1A.ClientID & "'</script>")

this could be the answer thanks for your attention mplungjan also i have 10 itens do i need to write for each one this line or isthere a method to include
image1a
image2a
....
image10a

to the script you did the write answer after your answer i will send you point it is not important this second question's answer i just don't wnat to close before ask this method also please look at this question also:

http://www.experts-exchange.com/Programming/Languages/Scripting/JScript/Q_24551635.html
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 150 total points
ID: 24802966
response.writeln("<script>")
response.writeln("var imgs = new Array()")
for (.....)
response.writeln("imgs[imgs.length]='" + Image[?].ClientID + "'];")
response.writeln("</script>")

I do not know aspnet enough to give you what goes in the [?]
0
 
LVL 1

Author Comment

by:CahitEy
ID: 24803299
Thanks this is very good answer ...
0
 
LVL 1

Author Closing Comment

by:CahitEy
ID: 31600667
script side is allright for the code behind of asp.net gives idea how to make it easy to connect to asp.net to jscript code
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

689 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