Set an asp:Label control from javascript - how?

Discussion in 'ASP .Net Web Controls' started by James Radke, Nov 4, 2003.

  1. James Radke

    James Radke Guest

    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
     
    James Radke, Nov 4, 2003
    #1
    1. Advertising

  2. 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.
     
    Jacob Yang [MSFT], Nov 5, 2003
    #2
    1. Advertising

  3. James Radke

    Jim Guest

    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];
    > }
    > </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
    >
    >
    >.
    >
     
    Jim, Nov 5, 2003
    #3
  4. James Radke

    James Radke Guest

    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

    "Jacob Yang [MSFT]" <> wrote in message
    news:Zd$...
    > 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.
    >
     
    James Radke, Nov 7, 2003
    #4
  5. 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.
     
    Jacob Yang [MSFT], Nov 10, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moondaddy
    Replies:
    1
    Views:
    17,183
    Steven Cheng[MSFT]
    Apr 2, 2004
  2. Shapper
    Replies:
    2
    Views:
    768
    Scott Mitchell [MVP]
    May 7, 2005
  3. Josef K.

    <label><div></div></label> allowed?

    Josef K., May 20, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    13,738
    Josef K.
    May 22, 2005
  4. Praveen
    Replies:
    1
    Views:
    1,053
    Rob Williscroft
    Nov 5, 2006
  5. Knut Krueger
    Replies:
    8
    Views:
    325
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page