Set an asp:Label control from javascript - how?

J

James Radke

Hello,

I am displaying an .ASPX page via windows.showModalDialog (to simulate a pop
up modal windows from a web page) from a javascript function and am
definining attributes to be passed to the modal dialog as follows:

function lineitemnotes(linnum, delnum) {
var myattributes = new Array(linnum,delnum)
var cRetValue =
window.showModalDialog("\LineItemNotes.htm",myattributes,"edge: raised;
dialogHeight: 37; dialogWidth: 35; center: yes; help: no; resizable:
no; status: no; scroll: no; toolbar: no;");
if (cRetValue != null)
{
__doPostBack('_ctl1$_ctl0$btnProcessNotes','');
}
}

Then in the web page that is presented in the pop up modial dialog window I
have

<script language=javascript>
function doInit() {
var linnum = "";
var delnum = "";
var MyArgs = new Array(linnum, delnum);
MyArgs = window.dialogArguments;
this.document.getElementById("lblLine").Text = MyArgs[0];
this.document.getElementById("lblDelivery").Text = MyArgs[1];
}
</script>

which is called from the BODY statement as follows:

<body MS_POSITIONING="FlowLayout" onload="doInit();">


Now for my question - the this.document.getElementById works, but I can not
set the .Text element? I want to set the label so that it shows the value
on the screen, AND so that I can reference that value (via the label
controls .TEXT property) when I execute other functions from the screen.
Can someone assist me and let me know how I can set the label controls
correctly from javascript?

Thanks!

Jim
 
J

Jacob Yang [MSFT]

Hi James,

Based on my research and experience, I would like to share the following
information with you.

In the onload phrase, the elements in the current document have not been
ready. That is, the elements inside the current document are not available
for access.

To overcome this problem, I will suggest two ways.

1. Move the call to the doInit() from onload phrase to the end of the web
page, when the elements in the documents should have been ready for access.

2. Keep the call to the doInit() function unchanged (still call the
doInit() function in the onload phrase). However, instead assigning the
values to the appropriate elements directly, just store the values into
some page-scope javascript variables and at the end of the web page; we
then can assign those variables to the appropriate elements.

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jim

The .text property is only available to the control in
the .NET environment. You cannot acces this from
javascript. You must set the value of the control from
javascript.

-----Original Message-----
Hello,

I am displaying an .ASPX page via windows.showModalDialog (to simulate a pop
up modal windows from a web page) from a javascript function and am
definining attributes to be passed to the modal dialog as follows:

function lineitemnotes(linnum, delnum) {
var myattributes = new Array(linnum,delnum)
var cRetValue =
window.showModalDialog
("\LineItemNotes.htm",myattributes,"edge: raised;
dialogHeight: 37; dialogWidth: 35; center: yes; help: no; resizable:
no; status: no; scroll: no; toolbar: no;");
if (cRetValue != null)
{
__doPostBack('_ctl1$_ctl0$btnProcessNotes','');
}
}

Then in the web page that is presented in the pop up modial dialog window I
have

<script language=javascript>
function doInit() {
var linnum = "";
var delnum = "";
var MyArgs = new Array(linnum, delnum);
MyArgs = window.dialogArguments;
this.document.getElementById("lblLine").Text = MyArgs[0];
this.document.getElementById
("lblDelivery").Text = MyArgs[1];
 
J

James Radke

Jacob,

It seems that the label control doesn't present a value property, only the
innerText, etc.

So, I converted my label control to a textbox, set the readonly to true, and
the borderstyle to none.. then I was able to reference the field the way I
needed to to.

Thanks!

Jim
 
J

Jacob Yang [MSFT]

Hi James,

I am glad to know that the problem is resolved.

I am sorry for my misunderstanding in my previous post.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,816
Messages
2,569,711
Members
45,499
Latest member
BreannaWhi

Latest Threads

Top