DKR DKR - 1 month ago 13
ASP.NET (C#) Question

how to set text of <h4> from c# in asp.net

I have a popup created in bootstrap in my .aspx page.

<div id="myModal" class="modal fade " tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">

<div class="modal-title">
<h4 id="modaltext" runat="server" class="modal-body"></h4>

<div class="modal-footer">
<button type="button" data-dismiss="modal" onclick="show_loginpanel()" class="btn btn-primary">Okay</button>
</div>
</div>
</div>


In c# .cs file,

modaltext.InnerHtml = "Successful";


From c#, i cam calling a js function which shows above modal popup.

ScriptManager.RegisterStartupScript(this, GetType(), "Message", "showModal();", true);


JavaScript Function: showModal()

function showModal() {

$('#myModal').modal('show')

}


When I run my project, On popup there is no text displayed. tag is empty.

Can someone tell me what I am missing.

Thanks.

Answer

Use LiteralControl for things like this:

<h4><asp:Literal id="SuccessfulLine" runat=server /></h4>

Code behind:

SuccessfulLine.Text ="Successful";

EDIT:

You can achieve that with javascript too:

string successfullString = "Successful";
string js = @"$( document ).ready(function() {

     $('#modaltext').text('" + successfullString + "'@
     $('#myModal').modal('show');
})";

ScriptManager.RegisterStartupScript(this, GetType(), "Message", js , true);