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

x
?
Solved

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

Posted on 2009-07-07
12
Medium Priority
?
2,567 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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