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

Code Behind and functions

Hello,

I am currently new to .NET, as you can probably tell by my last two or three
threads!!!

Anyway, I am using code behind as much as possible - and am curious about
the way in which functions can be triggered.

It seems if I use an <asp:button...control, I can assign a function which
exisits on my .CS file, for example:
<asp:button... OnClick="Button_Click">

However, this function is not available on for example a standard <Atag:
<A href="#" OnClick="Button_Click" runat="server" />

I am *guessing* this is because the button submits the .net form, which
forces the page to read the CS file again, which is when it can execute the
various functions?

My question is, is it possible or sensible to try and access these functions
without using a form button?

Regards,

Gary.

Jan 26 '07 #1
8 1508
"Gary" <g@nospam.comwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
I am currently new to .NET, as you can probably tell by my last two or
three
threads!!!

Anyway, I am using code behind as much as possible - and am curious about
the way in which functions can be triggered.

It seems if I use an <asp:button...control, I can assign a function
which
exisits on my .CS file, for example:
<asp:button... OnClick="Button_Click">

However, this function is not available on for example a standard <Atag:
<A href="#" OnClick="Button_Click" runat="server" />
Each webcontrol implements its own set of "events" for want of a better
term - lots of controls have very similar events. However, server-side code
can include other methods which these events can call. E.g. you could write
a server-side method which added a record to a database every time a control
initiated a postback - a pretty pointless thing to do - but you wouldn't
need to write the database code in every event - each event would simply
call the method...
I am *guessing* this is because the button submits the .net form, which
forces the page to read the CS file again, which is when it can execute
the
various functions?
Sort of... ASP.NET adds a couple of hidden fields to the Request.Form
collection which tell it which control initiated the postback, and which
event to run.
My question is, is it possible or sensible to try and access these
functions
without using a form button?
Using the traditional model (i.e. not callbacks via AJAX etc), server-side
code is *only* available through a postback, and a control needs to be
contained within a <formobject for it to be able to initiate a postback...

I appreciate you're new to ASP.NET, so maybe you can describe a bit more
about what you're trying to achieve...?
Jan 26 '07 #2
I appreciate you're new to ASP.NET, so maybe you can describe a bit more
about what you're trying to achieve...?
Well one example is I want to do a Post Code lookup. I have a server side
function in my Cod Behind file called FindAddress

I currently have an <ASP:Button... onClick="FindAddress" /which does the
trick, however, I would like to instead use a hyperlink with the words
"Click here to search for an address" - which triggers the same behavior.

When I try and have an onClick="FindAddress" - it seems to be looking for a
client side javascript function which doesnt exist.

Cheers,

G.

Jan 26 '07 #3
I appreciate you're new to ASP.NET, so maybe you can describe a bit more
about what you're trying to achieve...?

Another example would be clicking a link which converts the contents of a
Textfield to all caps....in code behind I can use PostCode.Text.ToUper() -
but I have no way of accessing this without a post back?

Gary.

Jan 26 '07 #4
"Gary" <g@nospam.comwrote in message
news:uv**************@TK2MSFTNGP04.phx.gbl...
Well one example is I want to do a Post Code lookup. I have a server side
function in my Cod Behind file called FindAddress

I currently have an <ASP:Button... onClick="FindAddress" /which does the
trick, however, I would like to instead use a hyperlink with the words
"Click here to search for an address" - which triggers the same behavior.
You're using the wrong control - use an <asp:LinkButtoninstead - looks
like hyperlink, functions like a button... :-)
When I try and have an onClick="FindAddress" - it seems to be looking for
a client side javascript function which doesnt exist.
Yes, it will do...
Jan 26 '07 #5
"Gary" <g@nospam.comwrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
Another example would be clicking a link which converts the contents of a
Textfield to all caps....in code behind I can use PostCode.Text.ToUper() -
but I have no way of accessing this without a post back?
You need client-side JavaScript for that:
http://www.google.co.uk/search?sourc...pt+toUpperCase

Jan 26 '07 #6
You're using the wrong control - use an <asp:LinkButtoninstead - looks
like hyperlink, functions like a button... :-)

Bingo! I love usent :o)

Much appreciated - thanks for your help.

Gary.
Jan 26 '07 #7
You need client-side JavaScript for that:
http://www.google.co.uk/search?sourc...pt+toUpperCase

Excellent, i did this:
<asp:TextBox ID="PostCode" runat="server" CssClass="PostCode"
onKeyUp="javascript:this.value=this.value.toUpperC ase();"></asp:TextBox>

This changes your case as you type it, I will add an onSubmit as well to
catch anyone who enters the post code without a keyboard, such as copy and
paste via the mouse, with an "enter button" subit.

Works in IE 7.0 & FF 2.0 - will check earlier browsers later.

G.

Jan 26 '07 #8
"Gary" <g@nospam.comwrote in message
news:uK**************@TK2MSFTNGP05.phx.gbl...
Excellent, i did this:
<asp:TextBox ID="PostCode" runat="server" CssClass="PostCode"
onKeyUp="javascript:this.value=this.value.toUpperC ase();"></asp:TextBox>

This changes your case as you type it, I will add an onSubmit as well to
catch anyone who enters the post code without a keyboard, such as copy and
paste via the mouse, with an "enter button" subit.

Works in IE 7.0 & FF 2.0 - will check earlier browsers later.
According to Danny Goodman's "Dynamic HTML - The Definitive Reference",
onkeyup is supported from version 4 browsers, so you should be fine.
http://www.amazon.com/Dynamic-HTML-D...e=UTF8&s=books
Jan 26 '07 #9

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

Similar topics

3
by: CW | last post by:
I find it necessary to mix code-behind and non-code behind techniques sometimes. I have utility functions defined in a VB module. Is there anyway for me to call functions defined in VB module...
6
by: Jim | last post by:
Group, How would I go about firing a JavaScript method from a C# method in the aspx code behind file? It seems as though this could not be done since JavaScript is executed from within the Web...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
2
by: shaun duke | last post by:
I have been researching this over the last two days without success. I have a number of ultility functions that I want to make available to all pages. The pages will all be using code behind so...
3
by: aaa | last post by:
I fail to see the connection between the code behind and the raw HTML of the ASPX page how do you get variables and functions to communicate with each other? I cannot get this to even fire:...
7
by: Shapper | last post by:
Hello, When creating an ASP.NET/VB web site I place my code in a code behind page, i.e., aspx.vb. Sometimes I have functions which are common to all aspx files. Is it possible in page1.aspx...
21
by: Sandy | last post by:
Hello - I am using Visual Studio .Net. I need an example of how to construct a class that can be used throughout a project where I can include its subs and functions in various pages in the...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
2
by: Des | last post by:
I am trying to connect to SQL Server. I have written some pages that have got the line Dim strConn as String = ConfigurationSettings.AppSettings("Thermos") There is a valid line <add...
7
by: Bodyboarder20 | last post by:
Hey, I'm sure this is an easy question for most. I would like to create a class with a bunch of "library" functions... But I'm not sure how I would configure it so that I can call functions...
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
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
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...

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.