473,651 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ 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="Server Save"
OnClientClick=" SaveParam (<% Util.MaxTags %>)" />

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

Any idea ?

Philippe
Jun 27 '08 #1
7 6909
"PhilTheGap " <or****@noemail .noemailwrote in message
news:AD******** *************** ***********@mic rosoft.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="Server Save"
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.OnClientCl ick = 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="Server Save"
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="Server Save"
OnClientClick=" SaveParam (<% Util.MaxTags %>)" />

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

Any idea ?

Philippe
....OnClientCli ck="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 "FunctionNa me" can be defined in codebehind(publ ic 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/356a59a676948d0 3/2eec23b49e63dd9 6
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 CodeExpressionB uilder
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****@microsof t.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="Server Save"
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****@microsof t.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************ *************** *******@microso ft.com>
<BR************ **@TK2MSFTNGHUB 02.phx.gbl>
>In-Reply-To: <BR************ **@TK2MSFTNGHUB 02.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
6781
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 stuck: I have page of results obtained from a MySQL query presented as a table (the first column having checkboxes for each of the rows in the table, and all having the name "seqs"). I have set up a javascript (connected to a "toggle all" checkbox)...
5
3744
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 following code fragments in which I want to list through all files on a directory with a link to download each file by passing a filename and whether or not to force the download dialog box to appear.
9
12869
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 it is read-only) .. Is there any way to make <this> not read-only? I have simplified the following code. There is a Task class and a Data Class. I am trying to pass the task class by ref to the data class. public class Task {
21
3288
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 sFname, int w, int h) { FileStream fs = new FileStream(sFname, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); // Read data
10
2500
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++) { items = "item" + (i + 1);
14
20387
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 passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
5
13975
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 button? I searched a few things on Google but I find the javascript below most useful in my case but there is some problem that my code is not running: var test = document.getElementsByName("meal"); for (i = 0; i < test.length; i++) {
24
55168
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 EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
12
11073
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. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5615
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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 we have to send another system
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.