Vinayaka N Vinayaka N - 2 months ago 7
JSON Question

Display Message Using Json in asp.net

I am trying to display a simple message using Json Where I am going wrong, I could not understand please Help me. My JSON code is

<script type="text/javascript">
var text = '{ "R000092201": "EIN and Name should be same" }';

var obj = JSON.parse(text);

document.getElementById("demo").innerHTML = obj.R000092201;




My aspx code is

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


and my aspx.cs code is

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"]);
}

Answer

The Id of Label might not be the same on the client side. So, most probably js cannot get it. you can use this property on the label ClientIDMode="Static" or use a different client side getter like those of jquery. Where you can get a node by name ending in "demo".

$("span[id$='demo']") 

I hope it helps.