Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

setting value of label on parent page with javascript

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
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Avatar of scm0sml
scm0sml

ASKER

yeah but lblTest is test1.aspx whereas the code behind you are refering to is on test2.aspx?
Avatar of scm0sml

ASKER

Sorry I didn't clearly state that but I am using window.opener so there was a clue in there :)
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';"

Avatar of scm0sml

ASKER

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........?
Avatar of scm0sml

ASKER

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


try changing innerText to Text
Avatar of scm0sml

ASKER

same error......
getelementbyid to getElementById
Avatar of scm0sml

ASKER

still no joy.

Its rendering as:
<script>window.opener.document.forms(0).getElementById ('lblTest').innerText = 'gem';</script>
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland 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
SOLUTION
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
The question has been answered in good faith, you can't just delete the question when experts have spent time helping you