Search code examples
javascripthtmlasp.nettextarearunatserver

html textarea ignoring javascript when set to runat="server" in ASP


I'm quite new to html and asp.

The problem is that i've defined a textarea that resizes depending on the content it has (using javascript functions).

It works like a charm till i set that textarea to runat="server". Then the resizing doesn't work anymore.

Why is this? How can i fix it?


Solution

  • This could be due to changed id of controls have runat="server", you can user ClientIDMode="static" if you are using framework 4 or above or use the ClientID instead of id of control.

    Using ClientIDMode

    <textarea id="TextArea1" cols="20" rows="2" runat="server" ClientIDMode="static" ></textarea>
    

    Using ClientID

    <textarea id="TextArea1" cols="20" rows="2" runat="server" ></textarea>
    

    In javascript

      TextArea1 = document.getElementById("<%= TextArea1.ClientID %>");