如何在asp.net中从c#设置<h4>的文本

Dhe*_*mar 2 .net javascript c# asp.net bootstrap-modal

我的 .aspx 页面中有一个在 bootstrap 中创建的弹出窗口。

<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>
Run Code Online (Sandbox Code Playgroud)

在 c# .cs 文件中,

modaltext.InnerHtml = "Successful"; 
Run Code Online (Sandbox Code Playgroud)

从 c# 中,我正在调用一个显示在模态弹出窗口上方的 js 函数。

 ScriptManager.RegisterStartupScript(this, GetType(), "Message", "showModal();", true);
Run Code Online (Sandbox Code Playgroud)

JavaScript 函数:showModal()

function showModal() {

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

}
Run Code Online (Sandbox Code Playgroud)

当我运行我的项目时,在弹出窗口中没有显示任何文本。<h4>标签为空。

有人可以告诉我我错过了什么。

myb*_*ame 5

将 LiteralControl 用于这样的事情:

<h4><asp:Literal id="SuccessfulLine" runat=server /></h4>
Run Code Online (Sandbox Code Playgroud)

后面的代码:

SuccessfulLine.Text ="Successful";
Run Code Online (Sandbox Code Playgroud)

编辑:

你也可以用 javascript 来实现:

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

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

ScriptManager.RegisterStartupScript(this, GetType(), "Message", js , true);
Run Code Online (Sandbox Code Playgroud)