Masterpage - jscript - runat=server problem

Discussion in 'ASP.NET 2.0' started by Jugs0101, Feb 9, 2007.

  1. Hi

    I don't know if anyone can help. My problem is this (in it's simplest form) :

    I create a new Web Form in Asp.Net, and give it a Masterpage file to use as a template.
    I place a textbox control on it (inside the ContentPlaceholder) with the tag runat='server' and an ID of 'textbox01'.
    If I then create any javascript on the page that attempts to get hold of the control by using the code

    var txt = document.getElementById("textbox01");

    It fails to find it.

    If I don't use the runat='server' tag, it also finds it fine.
    If I use exactly the same code WITHOUT usig a Masterpage but with runat='server', it finds it fine.

    Has anybody else come across the same problem, or am I missing something essential here?
    I am fairly new to the whole Ajax thing.

    Any suggestions would be greatly appreciated, thanks,

    Jugs
     
  2. change this...

    var txt = document.getElementById("textbox01");

    to this...

    var txt = document.getElementById("<%=textbox01.ClientID%>");


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  3. Joel,


    You can't believe my elation when this morning I woke up to find a reply to my email, form yourself, and it worked first time!


    You wouldn't believe the hoops I've been jumping through and the headaches I've had with it. It's so obvious too.


    Oh well, such is life.


    Thanks very much Joel, I can get on with my life now [​IMG] !!


    Jugs
     
  4. Hehe, ya I've had that same before ;)


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     

Share This Page