ASP.Net 1.1 Client Script

Discussion in 'ASP .Net' started by =?Utf-8?B?Z24=?=, Feb 24, 2006.

  1. I have an asp.net page with client side javascript. In the script I can get
    a control and read its properties by using
    document.getElementById('txtDBName'). But if I try to set any of the
    properties of this control it doesn't work; for example the code line
    document.getElementById('txtDBName').value = 'hosted';. Can anyone explain
    why this is.

    I have other pages where I do the same thing in client javascript and those
    pages work fine but on this one page this doesn't work. I have compared
    pages and I see no differences in the page that doesn't work and the page
    that does work.
     
    =?Utf-8?B?Z24=?=, Feb 24, 2006
    #1
    1. Advertising

  2. The statement document.getElementById('txtDBName').value = 'hosted'; would
    fail to produce an outcome if there were no control with that ID found. This
    could happen if you are referring to a server control that is within another
    server control (e.g. a textbox within a datagrid) where the ClientID would
    look like this: datagrid1:txtDBName.

    Try always to check if the getElementById function returned a null or an
    object, e.g.
    var txtBox = document.getElementById('txtDBName');
    if (txtBox!=null)
    {
    txtBox.value = "hosted";
    }
    else
    {
    alert("could not find a textbox with id='txtDBName'" );
    }
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "gn" wrote:

    > I have an asp.net page with client side javascript. In the script I can get
    > a control and read its properties by using
    > document.getElementById('txtDBName'). But if I try to set any of the
    > properties of this control it doesn't work; for example the code line
    > document.getElementById('txtDBName').value = 'hosted';. Can anyone explain
    > why this is.
    >
    > I have other pages where I do the same thing in client javascript and those
    > pages work fine but on this one page this doesn't work. I have compared
    > pages and I see no differences in the page that doesn't work and the page
    > that does work.
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Feb 24, 2006
    #2
    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. NWx
    Replies:
    3
    Views:
    23,638
  2. Magnus Blomberg
    Replies:
    3
    Views:
    745
    Magnus Blomberg
    Apr 14, 2005
  3. Boss302
    Replies:
    0
    Views:
    1,102
    Boss302
    Nov 21, 2006
  4. =?Utf-8?B?TG93bGFuZGVy?=
    Replies:
    0
    Views:
    391
    =?Utf-8?B?TG93bGFuZGVy?=
    Mar 27, 2007
  5. Andrea Williams

    Adding client-script to handle client events

    Andrea Williams, Apr 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    143
    Andrea Williams
    Apr 12, 2004
Loading...

Share This Page