0

When i click on submit, I want to add a div saying "Hi". But the below code does not work when i put the submit button in the form. It works only if I remove the runat="server" but without this my button cannot work.

    <script>
                    $(function () {
                        $('#submitThreadBtn').click(function () {
                            $('.divtext').append("<div><p>Hi</p></div>")
                            });
                    });
    </script>
        
<form runat="server">
        <div class="form-group">
             <label for="TA_AS_desc">Description: </label>
             <textarea class="form-control" rows="5" name="nm_AS_desc" id="TA_AS_desc" required></textarea>
        </div>
        <input class="btn btn-dark" type="submit" id="submitThreadBtn" value="Submit" runat="server" onserverclick="submitThreadBtn_ServerClick" />
    </form>
    
    <div class="divtext">
    
    </div>
ASh
  • 34,632
  • 9
  • 60
  • 82
anonymous
  • 19
  • 2
  • 1
    When button is clicked you want javascript to be executed and also the server side code be executed? The server side code execution causes the page to refresh and that's why any DOM changes done by javascript will be gone and new page will be rendered... Can you explain little bit more on the use case you are trying to implement? – Chetan Dec 29 '20 at 07:14

1 Answers1

0

The runat="server" tag in ASP.NET allows the ability to convert/treat most any HTML element as a server-side control that you can manipulate via code at generation time. Some controls have explicit implementations, others simply revert to a generic control implementation.

Visit https://stackoverflow.com/questions/11510502/understanding-the-runat-server-attribute#:~:text=The%20runat%3D%22server%22%20tag,to%20a%20generic%20control%20implementation

Kd Nimavat
  • 282
  • 1
  • 11