2016-10-23 4 views
1

私の.aspxページにブートストラップで作成されたポップアップがあります。 C#のは.csファイルで<h4>のテキストをasp.netのC#から設定する方法

<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> 

modaltext.InnerHtml = "Successful"; 

のC#から、私はモーダルポップアップの上に示しJS関数を呼び出しています。私は私のプロジェクトを実行すると、ポップアップで表示されたテキストがありません

function showModal() { 

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

} 

showModal():

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

JavaScriptの機能。 <h4>タグは空です。

誰かが私に行方不明を教えてもらえますか?このようなことのために

答えて

4

使用LiteralControl:

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

コードの背後にある:

SuccessfulLine.Text ="Successful"; 

EDIT:

あなたもJavaScriptでそれを達成することができます

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

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

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

お時間をありがとう。私はあなたが言ったように変更を加えましたが、まだテキストは空です。 –

+0

@DKR document.readyでshowModal()メソッドを呼び出す場所はどこですか? – mybirthname

+0

私はこのボタンをクリックしてC#から呼び出しています: "ScriptManager.RegisterStartupScript(this、GetType()、" Message "、" showModal(); "、true);" –

関連する問題