Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert html code section into a particular place using codebehind on page load

I have an aspx page where I need to check and display an error message on the page on page_load. The error message is below:

<div class="errorMessage">The user ID or password you entered does not match our records. Please try again. <br /> 
        You may also securely recover your <a href="#">User ID</a> or reset your <a href="#">Password</a> online. 
    </div>

this code block should be added to the page after chechking some conditions...and that part and some other functions are implemented in code behide function page_load()

how do i do this using only the behind the code in page_load() function without writing it inline in the aspx file?

like image 380
Dilan87 Avatar asked Apr 09 '12 15:04

Dilan87


1 Answers

Create a div with an ID and a runat="server":

<div ID="divErrorMessage" runat="server" class="divErrorMessage"></div>

Then from your Page_Load event in the code behind, you can set the inner html of the div:

divErrorMessage.InnerHtml = "Your message";

Setting the flag, runat="server" makes the control available in the code behind

like image 190
Halceyon Avatar answered Oct 13 '22 00:10

Halceyon