Modal popup not showing with runat=server on

I hope this is a simple one for someone to answer.

If i have a button that allows a user to edit something on the page, they can click on

<a href="#editpage" data-toggle="modal">Edit this page</a>

This then opens a modal on the page with the following DIV

<div id="editpage" class="modal" tabindex="-1" role="dialog">
    This is the content in my modal

The issue I am having is that when I add a runat=”server” to the modal’s div tag, so that I can determine if the user can even see/inspect the page source if they are not a moderator,, that the modal no longer pops up when i click on my edit button.

Is there anything I can do so that I can still control if the modal is rendered from code-behind based on logic there, and still have the edit to modal click function still work without turning it into a server control.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Found the answer which was to wrap the modal div in another div or placeholder tag and then control that from the server side controls. This meant that the modal’s div did not have it’s ID modified due to the server side assignment and therefore I am now able to remove this markup entirely if the user is not a moderator.

<asp:Panel ID="editpage_panel" runat="server" Visible="false">
 -- modal here

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x