Passing Server side variable to JavaScript?

Discussion in 'ASP .Net' started by rockdale, Jun 1, 2006.

  1. rockdale

    rockdale Guest

    Hi, All:

    How can I achieve this?

    I have a Function in JavaScript and this function requires an argument
    which retruns from a backend C# function.

    I tried the following, but keep getting error "CS1525: Invalid
    expression term '<' "

    I remeber we can do something like this in ASP. ?

    <asp:linkbutton id="lbnQuery"
    CssClass="NormalLinkSmall" runat="server" Text="Query"

    Thanks for your help
    rockdale, Jun 1, 2006
    1. Advertisements

  2. Set the event from codebehind:

    lbnQuery.Attributes.Add("onclick", "myJavaScriptFunc(" +
    CSharpFuncReturnsString() + ");");

    If the CSharpFuncReturnsString returns a string that contains something
    that isn't a number, you have to put apostrophes around the value. And
    if the value can contain apostrophes or backslashes, you have to escape
    them by replacing \ with \\ and ' with \':

    lbnQuery.Attributes.Add("onclick", "myJavaScriptFunc('" +
    CSharpFuncReturnsString().Replace("\\", "\\\\").Replace("'", "\\'") +
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jun 1, 2006
    1. Advertisements

  3. rockdale


    Jun 11, 2012
    Likes Received:
    bhaskarareddy, Jun 11, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.