473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to pass a C# parameter as an argument of a javascript method ?

Hi,

I've tried this:

<asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave"
OnClientClick="SaveParam (<% Util.MaxTags %>)" />

but if fails... Util is a C# class, MaxTags a static member.

Any idea ?

Philippe
Jun 27 '08 #1
7 6899
"PhilTheGap" <or****@noemail.noemailwrote in message
news:AD**********************************@microsof t.com...
but if fails... Any idea ?
Can you be a bit more specific, please...?

In what way(s) does it fail...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2
On Jun 12, 12:06 pm, "PhilTheGap" <ori...@noemail.noemailwrote:
Hi,

I've tried this:

<asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave"
OnClientClick="SaveParam (<% Util.MaxTags %>)" />

but if fails... Util is a C# class, MaxTags a static member.

Any idea ?

Philippe
Hi Philippe,

Do it in code:
Save.OnClientClick = string.Format("SaveParam ('{0}');",
Util.MaxTags);

Mykola
http://marss.co.ua
Jun 27 '08 #3
PhilTheGap used his keyboard to write :
Hi,

I've tried this:

<asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave"
OnClientClick="SaveParam (<% Util.MaxTags %>)" />

but if fails... Util is a C# class, MaxTags a static member.

Any idea ?

Philippe
You might provide a bit more info about the way it "fails"
(compile-time, run-time? error message? behaviour you didn't expect?)

But maybe try <%= Util.MaxTags %>

<% ... %means "execute this"
<%= ... %means "replace with this value"

Hans Kesting
Jun 27 '08 #4
On Jun 12, 11:06*am, "PhilTheGap" <ori...@noemail.noemailwrote:
Hi,

I've tried this:

<asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave"
OnClientClick="SaveParam (<% Util.MaxTags %>)" />

but if fails... Util is a C# class, MaxTags a static member.

Any idea ?

Philippe
....OnClientClick="SaveParam()" />

void SaveParam()
{
var x = <%=Util.MaxTags%>;
...
Jun 27 '08 #5
Hi Phil,

In line express like <%= %cannot be used in server control's
attribute/property, it can only be embeded in plain html fragment. Here is
a blog article mentioned it:

#From the Suggestion Box: Why can't you use code expressions for
properties?
http://weblogs.asp.net/leftslipper/a...de-expressions
-in-properties.aspx

For your scenario, as other member suggested, you can consider define the
javascript function without parameter and manually set the variable in the
javascript function definition like below:

==========
<asp:Control OnClientClick="js_function();" />
.........

<script ....>
function js_function()
{
var param = <%= your server-side code %>
}
</script>
==================

Also, for server control property, it support two kind of inline
expresssion:
1. DataBinding expression <%# %>

You can use it to set attributes such as:

<asp:TextBox ... Text='<%# FunctionName() %>' .../>

the "FunctionName" can be defined in codebehind(public or protected),
however, to make the databind expression get executed, you need to call
"DataBind" method on the control or it s parent control.

Here is former thread I've mentioned something on this:

http://groups.google.com/group/micro...rk.aspnet/brow
se_thread/thread/356a59a676948d03/2eec23b49e63dd96
2. There is a new feature in ASP.NET 2.0 called custom Expression Builder

#Expression Builders in ASP.NET 2.0
http://www.beansoftware.com/ASP.NET-...n-Builder.aspx

#The CodeExpressionBuilder
http://weblogs.asp.net/infinitiesloo...odeExpressionB
uilder.aspx

You can use such expression builde to embed code expression into server
control's tag to as to intialize control property with some programmtic
values.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "PhilTheGap" <or****@noemail.noemail>
Subject: How to pass a C# parameter as an argument of a javascript method ?
Date: Thu, 12 Jun 2008 11:06:23 +0200
>
Hi,

I've tried this:

<asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave"
OnClientClick="SaveParam (<% Util.MaxTags %>)" />

but if fails... Util is a C# class, MaxTags a static member.

Any idea ?

Philippe
Jun 27 '08 #6
Thanks a lot Steven !
Jun 27 '08 #7
You're welcome Phil,

Have a nice day!

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "PhilTheGap" <or****@noemail.noemail>
References: <AD**********************************@microsoft.co m>
<BR**************@TK2MSFTNGHUB02.phx.gbl>
>In-Reply-To: <BR**************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: How to pass a C# parameter as an argument of a javascript
method ?
>Date: Fri, 13 Jun 2008 09:30:11 +0200
>
Thanks a lot Steven !
Jun 27 '08 #8

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

Similar topics

3
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little...
5
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the...
9
by: Jay Douglas | last post by:
Hello, I am needing to pass a class object (this) by reference to a method in a different class. When I do the following code I get the error (Cannot pass '<this>' as a ref or out argument because...
21
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.