我想顯示一個簡單的消息使用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'爲空 –