473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Passing Server side variable to JavaScript?

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

Jun 1 '06 #1
1 1799
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

Jun 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonas Daunoravicius | last post by:
The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script language="javascript" type="text/javascript"> function...
3
by: Gung Ho | last post by:
Has anyone had success passing variable data between ASP scripts and Javascript?
1
by: Patrice | last post by:
Hi, I'm trying to use a javascript function passing a vb variable. I don't understand why it doesn't work. Can someone help me? Thanks in advance. Here is my javascript function used to...
6
by: Mark Anderson | last post by:
I have code to develop result page links (like a search engine) for some results being passed from a database where I've no server-sdide acces - thus JS. The code is below and works fine except...
2
by: RootShell | last post by:
Hello First of all i know that PHP is a server side, and JavaScript is a Client side programming language, but i need to know if there is any way i can add the variable "countDownInterval" from...
11
by: comp.lang.php | last post by:
On one of my sites, I have a TCL CGI script that has a security hole in spite of it having effective server-side validation (the fact that it's CGI IS its security hole). The front end is a PHP...
8
by: Mike Fellows | last post by:
Ok, im not sure if this is at all possible and if it is how i go about it is beyond me i have a piece of client side code that requires a piece of data from the server side (an ID number in this...
1
by: Derrick | last post by:
Say I have main.aspx, that opens dialog.aspx in a browser dialog type window. User clicks "search" and a list is populated in dialog.aspx. I would like to be able to have the user select a few...
5
by: Paul | last post by:
Just wondering if someone could provide an example of passing a variable from the code behind to javascript in vb. I want to have one control have focus with the page loading with one condition...
1
by: | last post by:
Hi, 1st, I did a search and could not find any info on this, the Google results were good, but I'm still have issues...So any help will be great. I have a frame page, which contains 3 frames...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.