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"
    onClick="myJavaScriptFunc(<%=CSharpFuncReturnsString()%>)"
    CssClass="NormalLinkSmall" runat="server" Text="Query"
    BorderStyle="none"></asp:linkbutton>

    Thanks for your help
    -Rockdale
     
    rockdale, Jun 1, 2006
    #1
    1. Advertising

  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("'", "\\'") +
    "');");


    rockdale wrote:
    > 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"
    > onClick="myJavaScriptFunc(<%=CSharpFuncReturnsString()%>)"
    > CssClass="NormalLinkSmall" runat="server" Text="Query"
    > BorderStyle="none"></asp:linkbutton>
    >
    > Thanks for your help
    > -Rockdale
    >
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jun 1, 2006
    #2
    1. Advertising

  3. rockdale

    bhaskarareddy

    Joined:
    Jun 11, 2012
    Messages:
    2
    bhaskarareddy, Jun 11, 2012
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ken busse
    Replies:
    2
    Views:
    472
  2. Mike Fellows
    Replies:
    8
    Views:
    450
    Eliyahu Goldin
    Jun 29, 2004
  3. shil
    Replies:
    2
    Views:
    2,075
    Eliyahu Goldin
    Jan 2, 2007
  4. Jack
    Replies:
    3
    Views:
    231
  5. Matt
    Replies:
    2
    Views:
    920
    Anthony Judd
    Sep 25, 2004
Loading...

Share This Page