473,396 Members | 1,967 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,396 software developers and data experts.

function samples

in the visual studio .NET samples that come with the product, why do
javascript functions all have the parameters below. Even though, the event
(like Onclick) which is calling it doesn't have any parameters.

private function somename(sender:Object, e:EventArgs)

thanks.

Nov 18 '05 #1
3 2306
I belive you are confusing a server OnClick event with a client side onclick
event. The OnClick(s as object, e as eventargs) is for server side stuff.
"Mark Kurten" <ma*********@acordia.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
in the visual studio .NET samples that come with the product, why do
javascript functions all have the parameters below. Even though, the event (like Onclick) which is calling it doesn't have any parameters.

private function somename(sender:Object, e:EventArgs)

thanks.

Nov 18 '05 #2
Hi Mark,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you'd like to know why there are some script
function in the page's source file and they have some parameters declared,
however, in the control's event attribute, the calling function don't take
any parameter such as:
private function somename(sender:Object, e:EventArgs)
{
......
}

and we use this fuction for a control 's "OnClick" event like:
<asp:Button id="btn" OnClick="somename" />

If there is anything I misunderstood, please feel free to let me know.

As for this question, I think it i because the different program style of
clientside script block and serverside code block:
1.Generally, if we develop the ASP.NET page in VS.NET, when we create a web
page, the IDE will help use create a code-hehind class file together with
the page. Then, we can write the serverside event handler, such as server
control's click even's handler in the code-behind class file(.aspx.cs or
..aspx.vb files). For example:
private void Page_Load(object sender, System.EventArgs e) // page's click
event handler
{
................

}

private void btnPrint_Click(object sender, System.EventArgs e) // a certain
button's click handler
{
................

}

these serverside event handlers normally all take two paramteres,one
(sender) is the source of the event, and the other (e, EventArgs or its
derived class) contains some infos of the event. When we add the handler to
a certain control's event's handler collection, we only need to provide the
function's name , not argument list needed, for example:

this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
this.Load += new System.EventHandler(this.Page_Load);

However, if we don't use the code-behind page class file, then we just
write these handler functions in the aspx file and in such code blocks as
below:
<script language="C#" runat="server">
.....
private void btnPrint_Click(object sender, System.EventArgs e) // a certain
button's click handler
{
................

}
</script>

and we also speify the handler for a ASP.NET server control in the file
like:
<asp:button id="btnPrint" runat="server" Text="Print"
OnClick="btnPrint_Click"></asp:button>
Just the function name, no parameter needed. Since the ASP.NET runtime will
help you to generate the "sender" and "e" object from the control
automaitcally.
For more detailed info on event handler in ASP.NET serverside , you may
view the following reference in MSDN:
http://msdn.microsoft.com/library/en...andlers.asp?fr
ame=true

#Creating Event Handlers in Web Forms Pages
http://msdn.microsoft.com/library/en...ngEventHandler
sInWebFormsPages.asp?frame=true
2. The function I discussed in 1. is the server side code in ASP.NET. In
addition, we can write client side script code such as javascript in the
aspx page source file, for example:
<script language="javascript">
function jsfn()
{
alert("hello world!");
}

function sayHello(name)
{
alert("hello world" + name);
}
</script>

But be careful, such client side script is quite different from the
serverside code, they only runat the client's browser. You can see the
<script ..> block doesn't have "runat=server". And the client side script's
function could also take paramter or doesn't take parameter. I've shown the
two condition in the above example.
If you need more information on clientside scripting, you may view the
following link for reference:

#javascript overview and examples
http://msdn.microsoft.com/library/en...t.asp?frame=tr
ue
Please check out the above items to see whether they help. If you need any
further assistance, please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
thank you very much for the detailed explanation...

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:C1**************@cpmsftngxa07.phx.gbl...
Hi Mark,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you'd like to know why there are some script
function in the page's source file and they have some parameters declared,
however, in the control's event attribute, the calling function don't take
any parameter such as:
private function somename(sender:Object, e:EventArgs)
{
.....
}

and we use this fuction for a control 's "OnClick" event like:
<asp:Button id="btn" OnClick="somename" />

If there is anything I misunderstood, please feel free to let me know.

As for this question, I think it i because the different program style of
clientside script block and serverside code block:
1.Generally, if we develop the ASP.NET page in VS.NET, when we create a web page, the IDE will help use create a code-hehind class file together with
the page. Then, we can write the serverside event handler, such as server
control's click even's handler in the code-behind class file(.aspx.cs or
aspx.vb files). For example:
private void Page_Load(object sender, System.EventArgs e) // page's click
event handler
{
...............

}

private void btnPrint_Click(object sender, System.EventArgs e) // a certain button's click handler
{
...............

}

these serverside event handlers normally all take two paramteres,one
(sender) is the source of the event, and the other (e, EventArgs or its
derived class) contains some infos of the event. When we add the handler to a certain control's event's handler collection, we only need to provide the function's name , not argument list needed, for example:

this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
this.Load += new System.EventHandler(this.Page_Load);

However, if we don't use the code-behind page class file, then we just
write these handler functions in the aspx file and in such code blocks as
below:
<script language="C#" runat="server">
....
private void btnPrint_Click(object sender, System.EventArgs e) // a certain button's click handler
{
...............

}
</script>

and we also speify the handler for a ASP.NET server control in the file
like:
<asp:button id="btnPrint" runat="server" Text="Print"
OnClick="btnPrint_Click"></asp:button>
Just the function name, no parameter needed. Since the ASP.NET runtime will help you to generate the "sender" and "e" object from the control
automaitcally.
For more detailed info on event handler in ASP.NET serverside , you may
view the following reference in MSDN:
http://msdn.microsoft.com/library/en...andlers.asp?fr ame=true

#Creating Event Handlers in Web Forms Pages
http://msdn.microsoft.com/library/en...ngEventHandler sInWebFormsPages.asp?frame=true
2. The function I discussed in 1. is the server side code in ASP.NET. In
addition, we can write client side script code such as javascript in the
aspx page source file, for example:
<script language="javascript">
function jsfn()
{
alert("hello world!");
}

function sayHello(name)
{
alert("hello world" + name);
}
</script>

But be careful, such client side script is quite different from the
serverside code, they only runat the client's browser. You can see the
<script ..> block doesn't have "runat=server". And the client side script's function could also take paramter or doesn't take parameter. I've shown the two condition in the above example.
If you need more information on clientside scripting, you may view the
following link for reference:

#javascript overview and examples
http://msdn.microsoft.com/library/en...t.asp?frame=tr ue
Please check out the above items to see whether they help. If you need any
further assistance, please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

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

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
1
by: Fisch von Gestern | last post by:
I have tried to run the extension function/element examples provided with the Xalan-J download. I believe that my classpath is correct, and that my versions are up-to-date. However, I can't get...
0
by: EasyRider41 | last post by:
I am trying to merge to scripting samples I for on a source code web site and having limited luck. Then first one is called Zebra Tables witch colors alternate rows of a table to look beter. The...
0
by: Sean Newton | last post by:
I am absolutely bewildered by now by the Microsoft.Samples SSPI and Security assemblies. I've been trying to set these up in a very straightforward harness in the way that I'd like to be able to...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
10
by: Don Wash | last post by:
Hi! I'm pretty frustrated learning ASP.NET. I'm learning ASP.NET by downloading samples from various ASP.NET websites and none of the samples worked so far. The SAME error was shown whenever I...
4
by: shachar | last post by:
hi all. i'm looking for a simple example of how to pass optionaly, an array to a function. if the array isn't there (it's optional) i want to know about it. thanks.
1
by: David Lozzi | last post by:
Hello, I have a user control that saves data. When the data is saved, I need to call a function in the parent page from the user control to initiate something else. I know I can set it up so...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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.