我想显示一个简单的消息使用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代码
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行给出错误,那么它也不会工作 –
我认为如果演示Label在contentplaceholder内。那么它的id在客户端可能会有所不同。如果是这种情况,您可以使用服务器控件的这个属性来确保它在客户端也具有相同的ID。 ClientIDMode =“Static” –
显示......无法设置属性'innerHTML'为空 –