私はJsonを使用して簡単なメッセージを表示しようとしていますが、どこが間違っているのか理解できませんでした。私のJSONコードはメッセージ表示asp.netでJsonを使用
<script type="text/javascript">
var text = '{ "R000092201": "EIN and Name should be same" }';
var obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.R000092201;
私のaspxコードが
<div id="divErrorList" runat="server" style="line-height: 25px; font-size: 16px; font-weight: bold; color: #E41B17; padding-left: 20px; margin-top: 1%; border: 1px dashed red; background-color: #FBEFEF;">
<div>
Rejection Code:
<asp:Label ID="lblRejectionReason" runat="server" Text=""></asp:Label>
</div>
<div>
Rejection Reason:
<asp:Label ID="demo" runat="server" Text=""></asp:Label>
</div>
</div>
であり、私のaspx.csコードは、ラベルのIdは上と同じではないかもしれません
if (Convert.ToString(ldr["rejection"]) == "R0000-922-01")
{
divErrorList.Visible = true;
lblRejectionReason.Text = Convert.ToString(ldr["rejection"]);
//ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert();", true);
// lblrejectionmsg.Text = Convert.ToString(ldr["rejection_msg"]);
contSup.Visible = false;
editbtn.Visible = true;
}
else
{
divErrorList.Visible = true;
editbtn.Visible = false;
contSup.Visible = true;
lblRejectionReason.Text = Convert.ToString(ldr["rejection"]);
// lblrejectionmsg.Text = Convert.ToString(ldr["rejection_msg"]);
}
私を助けるためのみんなに感謝します。あなたのコードは問題ありませんが、それ以上のJS行がエラーを出している場合は動作しません。 –
デモラベルがcontentplaceholderの中にあると思います。そのidはクライアント側で異なるかもしれません。その場合、サーバーコントロールのこのプロパティを使用して、クライアント側で同じIDを持つことを確認できます。 ClientIDMode = "静的" –
表示されています...... nullのプロパティ 'innerHTML'を設定できません。 –