Solved

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

Posted on 2009-07-07
12
2,546 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
  • 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now