Link to home
Start Free TrialLog in
Avatar of CahitEy
CahitEy

asked on

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

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

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

what is the error?

Server or client side?

What does the javascript look like in the view-source?
Avatar of CahitEy
CahitEy

ASKER

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 ?
Sooo, please use view-source and see what it is called.

Avatar of CahitEy

ASKER

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
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/
Avatar of CahitEy

ASKER

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
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

Avatar of CahitEy

ASKER

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
Avatar of CahitEy

ASKER

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:

https://www.experts-exchange.com/questions/24551635/image-source.html
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CahitEy

ASKER

Thanks this is very good answer ...
Avatar of CahitEy

ASKER

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