473,653 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...c ontrol, 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 1517
"Gary" <g@nospam.comwr ote in message
news:e5******** ******@TK2MSFTN GP05.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...c ontrol, 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="FindAd dress" /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="FindAd dress" - 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.T oUper() -
but I have no way of accessing this without a post back?

Gary.

Jan 26 '07 #4
"Gary" <g@nospam.comwr ote in message
news:uv******** ******@TK2MSFTN GP04.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="FindAd dress" /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:LinkButton instead - looks
like hyperlink, functions like a button... :-)
When I try and have an onClick="FindAd dress" - 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.comwr ote in message
news:e%******** ********@TK2MSF TNGP03.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.T oUper() -
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:LinkButton instead - 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="PostC ode"
onKeyUp="javasc ript:this.value =this.value.toU pperCase();"></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.comwr ote in message
news:uK******** ******@TK2MSFTN GP05.phx.gbl...
Excellent, i did this:
<asp:TextBox ID="PostCode" runat="server" CssClass="PostC ode"
onKeyUp="javasc ript:this.value =this.value.toU pperCase();"></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
3731
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 from aspx form (i.e., code mixed in with html elements) or even call public shared functions from other code behind classes)?
6
4496
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 browser and C# is executed on the server. Thanks for your consideration, Jim
37
5949
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 in a separate file from the HTML. Apart from the obvious advantage if you have a separate designer and programmer, are there any other advantages to code behind? Most of the stuff I've seen so far uses code inside, but that's probably
2
1784
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 my plan is to create an assembly CommonFunctions.dll place it in the /bin folder for the application and import the namespace into the code behind where required. Here is an abstract of CommonFunctions.vb
3
1449
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: <script Language=C# runat=Server> public int myfunc() { int blah = 1;
7
2235
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 to use page1.aspx.vb and also a common file named global.aspx.vb which will hold all the functions common to all aspx files in a web site.
21
2122
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 project. I googled this and either I didn't use the correct words, or there doesn't seem to be much on it. Any help will be appreciated!
29
3667
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 id="Form1" method="post" runat="server"> <%
2
1323
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 key="Thermos" value="server=(local)\NetSDK; database=Thermos; integrated security=true;" /> In web.config This is working fine. What I want to do is move some of the code into a code behind file Functions.vb. This is where things are going wrong. The...
7
2245
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 from one "code" file from another "code behind" file.... Page1.aspx ---Page1.aspx.cs ---globallibrary.cs
0
8370
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...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8590
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...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
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
4147
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
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2707
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

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.