?
Solved

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

Posted on 2009-07-07
12
Medium Priority
?
2,565 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
Technology Partners: 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 450 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

771 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