Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Passing Server side variable to JavaScript?

Reply
Thread Tools

Passing Server side variable to JavaScript?

 
 
rockdale
Guest
Posts: n/a
 
      06-01-2006
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(<%=CSharpFuncReturnsStri ng()%>)"
CssClass="NormalLinkSmall" runat="server" Text="Query"
BorderStyle="none"></asp:linkbutton>

Thanks for your help
-Rockdale

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      06-01-2006
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(<%=CSharpFuncReturnsStri ng()%>)"
> CssClass="NormalLinkSmall" runat="server" Text="Query"
> BorderStyle="none"></asp:linkbutton>
>
> Thanks for your help
> -Rockdale
>

 
Reply With Quote
 
 
 
 
bhaskarareddy bhaskarareddy is offline
Junior Member
Join Date: Jun 2012
Posts: 2
 
      06-11-2012
hi

i hope it will help you
http://csharpektroncmssql.blogspot.c...-variable.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a value from server side to client side kimberly.walker@consultant.com ASP .Net 4 07-13-2006 09:07 AM
assign javascript variable value to VBScript server side variable Matt ASP General 2 09-25-2004 10:40 AM
Passing data from server side to client side? Mike Fellows ASP .Net 8 06-29-2004 03:28 PM
How can Server-Side variable'value be given to Client-Side variable by program Jack ASP General 3 01-29-2004 01:09 AM
Passing a text string from the server side to a client side function ken busse ASP .Net 2 11-24-2003 08:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57