Solved

setting value of label on parent page with javascript

Posted on 2011-02-14
13
525 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check if field exists SPUtility 5 48
Jquery Calculation 3 42
Date Picker is picky (about something) 4 42
Subtract dates in vb.net 6 34
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

751 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