You must Sign In to post a response.
  • Category: JQuery

    Error in passing value from cs to jquery

    Hi,

    I want to pass value from cs file to jquery file

    following is working code

    cs file

    protected void Page_Load(object sender, EventArgs e)
    {

    if (!IsPostBack)
    {
    Heading="Baiju";
    }
    }

    public string Heading { get; set; }

    jquery file

    $(document).ready(function () {
    var title = "<%=Heading%>";
    alert(title);

    });

    this is working fine and alert message is Baiju

    problem is if i remove jquery file and write the code in another js file and call it in the page

    like

    <script type="text/javascript" language="javascript" src="bd.js">

    it will not work

    then alertmessage will be

    "<%=Heading%>";


    How to solve this


    Regards

    Baiju
  • #765258
    Hi

    external js canot find your Heading property

    so you can use try label for this


    <asp:Label ID="lblHeading " runat="server"></asp:Label>




    $(document).ready(function () {
    var title = "<%=lblHeading %>";
    alert(title);
    });

    or

    $(document).ready(function () {
    var title = "<%=lblHeading.ClientID %>";
    alert(title);
    });


    if you use external js means you must mention ClientID for get value.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments