Solved

setting value of label on parent page with javascript

Posted on 2011-02-14
13
537 Views
Last Modified: 2012-05-11
Hi,

I have test1.aspx and test2.aspx

Test1.aspx simply has an asp:label an asp:textbox and a standard href link.

The link looks like:
<ahref="javascript:;" onclick="window.open('Test2.aspx?label=lblTest','cal','width=530,height=300,left=0,top=0')"><img src="Images/po.bmp" border="0" alt=""/></a>

This opens up test2.aspx fine.

Then on the page load of test2.aspx I have:
  Dim strScript As String = ""
        strScript = "<script>"

        strScript += "window.opener.document.forms(0).getelementbyid(lblTest).innerText = 'gem';"
        'strScript += "window.opener.document.forms(0).txtTest.value = 'gem';"


        strScript += "self.close()"
       
        strScript += "</" + "script>"

        ClientScript.RegisterClientScriptBlock(Me.GetType(), "PopUpwindowOpen", strScript)

As you can see the textbox line is commented out.

This works fine.

If its there on its own, the value gem gets written into the textbox and the page closes.

With the innertext line in though it is erroring.

Basically what I need to know is what is wrong with:
        strScript += "window.opener.document.forms(0).getelementbyid(lblTest).innerText = 'gem';"

to get it working.

The label gets rendered on test1.aspx as:
<span id="lblTest"></span>


Thanks in advance
0
Comment
Question by:scm0sml
[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
  • 6
  • 6
13 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34888116
change it to :
 strScript += "window.opener.document.forms(0).getelementbyid('" & lblTest.ClientID & "').InnerText = 'gem';"

0
 

Author Comment

by:scm0sml
ID: 34888154
yeah but lblTest is test1.aspx whereas the code behind you are refering to is on test2.aspx?
0
 

Author Comment

by:scm0sml
ID: 34888240
Sorry I didn't clearly state that but I am using window.opener so there was a clue in there :)
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34888399
change your link to this :
<a id="lnkOpenWindow" href="javascript:;" ><img src="Images/po.bmp" border="0" alt=""/></a>

in the code behind on test1.aspx put this in Page_PreRenderComplete :
lnkOpenWindow.Attributes.Add("Onclick", "window.open('Test2.aspx?label=' & lblTest.ClientId & ','cal','width=530,height=300,left=0,top=0')"

in the code behind on test2.aspx put this:
strScript += "window.opener.document.forms(0).getelementbyid('" & Request.QueryString("label") & "').InnerText = 'gem';"

0
 

Author Comment

by:scm0sml
ID: 34888572
Hi,

I'm presuming you haven't actually run that code as there are a number of errors in it that is stopping it from running........?
0
 

Author Comment

by:scm0sml
ID: 34888761
Right the script that is getting created is:
<script>window.opener.document.forms(0).getelementbyid('lblTest').innerText = 'gem';</script>

I'm getting:
Message: Object doesn't support this property or method
Line: 15
Char: 1
Code: 0
URI: http://localhost:3376/ImportPayments/Test2.aspx?label=lblTest


0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34888860
try changing innerText to Text
0
 

Author Comment

by:scm0sml
ID: 34888919
same error......
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34888955
getelementbyid to getElementById
0
 

Author Comment

by:scm0sml
ID: 34889012
still no joy.

Its rendering as:
<script>window.opener.document.forms(0).getElementById ('lblTest').innerText = 'gem';</script>
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 250 total points
ID: 34890026
Hmm i suspect the problem is that the label on the test1.aspx page is being rendered as a span.

try changing  the following line so there are no single quotes round the lblTest.ClientId :
lnkOpenWindow.Attributes.Add("Onclick", "window.open('Test2.aspx?label=" & lblTest.ClientId & ",'cal','width=530,height=300,left=0,top=0')"

Probably worth testing again at this point.
But I think you will need to change the following line removing the single quotes again and chaning innerText to innerHTML

strScript += "window.opener.document.forms(0).getElementById(" & Request.QueryString("label") & ").innerHTML = 'gem';"

This link may be of some help too :
http://www.htmlgoodies.com/beyond/javascript/article.php/3686901/How-to-Populate-Fields-from-New-Windows-Using-JavaScript.htm
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 34896146
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35016648
The question has been answered in good faith, you can't just delete the question when experts have spent time helping you
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

635 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