calling javascript function from asp.net

Discussion in 'ASP .Net' started by kimberly.walker@consultant.com, Dec 12, 2006.

  1. Guest

    I have a piece of code that calls the clientside it works ok when no
    values are passed ie window.alert ('this is a test'). But I have a
    value from a textbox example:
    function openemail()
    {
    var email = document.getElementbyID("txtEmailAddress").value;
    window.alert(email);
    }
    when I call this function
    string script = "<script language='javascript'>openemail();</script>";
    Page.RegisterClientScriptBlock("email", script);
    Its gives me an error saying missing object.
    Any help will be greatly appreciated
    , Dec 12, 2006
    #1
    1. Advertising

  2. Serge/XX Guest

    wrote:
    > I have a piece of code that calls the clientside it works ok when no
    > values are passed ie window.alert ('this is a test'). But I have a
    > value from a textbox example:
    > function openemail()
    > {
    > var email = document.getElementbyID("txtEmailAddress").value;
    > window.alert(email);
    > }
    > when I call this function
    > string script = "<script language='javascript'>openemail();</script>";
    > Page.RegisterClientScriptBlock("email", script);
    > Its gives me an error saying missing object.
    > Any help will be greatly appreciated
    >


    It is due to the fact that when the aspx page is rendered, your control
    txtEmailAddress will have a more complicated id based on page id and
    container control (if any).

    To solve your issue, just do this

    function openemail(theEmailAddressControl)
    {
    var email = document.getElementbyID(theEmailAddressControl).value;
    window.alert(email);
    }

    Then

    string script = "<script language='javascript'>" _
    "openemail(" & txtEmailAddress.ClientID & ");" _
    "</script>";
    Page.RegisterClientScriptBlock("email", script);

    Regards
    --
    Serge Driesen
    Serge/XX, Dec 12, 2006
    #2
    1. Advertising

  3. bruce barker Guest

    you are calling the function before the text control is parsed by the
    browser. try using RegisterStartupScript("openemail()")

    -- bruce (sqlwork.com)

    wrote:
    > I have a piece of code that calls the clientside it works ok when no
    > values are passed ie window.alert ('this is a test'). But I have a
    > value from a textbox example:
    > function openemail()
    > {
    > var email = document.getElementbyID("txtEmailAddress").value;
    > window.alert(email);
    > }
    > when I call this function
    > string script = "<script language='javascript'>openemail();</script>";
    > Page.RegisterClientScriptBlock("email", script);
    > Its gives me an error saying missing object.
    > Any help will be greatly appreciated
    >
    bruce barker, Dec 12, 2006
    #3
    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. szabelin
    Replies:
    6
    Views:
    14,173
    szabelin
    Aug 16, 2003
  2. Anatoly
    Replies:
    1
    Views:
    8,998
    =?Utf-8?B?TmlsZXNodw==?=
    Feb 17, 2004
  3. =?Utf-8?B?S0s=?=
    Replies:
    6
    Views:
    31,775
    errorocean
    Mar 22, 2010
  4. Andreas Lagemann
    Replies:
    8
    Views:
    477
    Mike Wahler
    Jan 10, 2005
  5. tiwy
    Replies:
    0
    Views:
    438
Loading...

Share This Page