[英]Display Message Using Json in asp.net
我正在嘗試使用Json顯示一條簡單消息我要去哪里了,我聽不懂,請幫幫我。 我的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"]);
}
標簽的ID在客戶端可能不相同。 因此,很可能js無法獲得它。 您可以在標簽ClientIDMode =“ Static”上使用此屬性,也可以使用與jquery不同的客戶端getter。 您可以在其中以“ demo”結尾的名稱獲取節點。
$("span[id$='demo']")
希望對您有所幫助。
只是我更改了腳本,主要是在Khalid Khan的幫助下,我在標簽中添加了ClietIDMode =“ Static” 。 Json代碼如下
<script type="text/javascript">
var text = '{ "R000092201": "EIN and Name should be same" }';
var obj = JSON.parse(text);
document.getElementById('lblrejectionmsg').innerHTML = obj.R000092201;
</script>
我的aspx代碼是
<div>
Rejection Reason:
<asp:Label ID="lblrejectionmsg" runat="server" Text="" ClientIDMode="Static"></asp:Label>
</div>
謝謝你們幫我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.