473,597 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programatically setting OnClick handler for asp:Button (how to do?)

Hi! I have an aspx that I've created which has an asp:Button in it. I
would like to be able to change the OnClick handler at runtime
(basically, I want this form to either edit or create a record, and I
want to change the procedure it calls depending on what it should be
doing). However, apparently the .OnClick member is read only?

(Sample:)

<script language="jscri pt">
function do_edit() {
...
do_action_btn.T ext = "Save";
do_action_btn.O nClick = "do_update" ;
}
....
</script>
<html>
<head>
</head>
<body>
<form id="page_form" runat="server" />
...
<asp:Button id="do_action_b tn" runat="server" />
...
</form>
</body>
</html>

----------

Alternately, if the above isn't possible, I can do something with
CommandButtons, but without a repeater/datagrid/datalist, I'm not sure
where to put the "OnItemComm and" property...

Thanks muchly,
Ricky Morse
Nov 18 '05 #1
2 2516

I haven't had much luck re-using buttons over multiple
post backs. There is a solution, however. You can use a
number of asp:Panels to hold sets of buttons (or whatever
you need to change between post backs). Create a Panel
holding the first "Edit" button, and a second Panel
holding the "Save" button with visibility=fals e. In
Edit_OnClick, set edit_panel.visi bility=false and
save_panel.visi bility=true. Obviously, you will need
different OnClick handlers for each button.

That's not exactly what you asked for, but it can
sometimes be a little cleaner than re-using buttons and
eventhandlers.

hth,
Matt
-----Original Message-----
Hi! I have an aspx that I've created which has an asp:Button in it. Iwould like to be able to change the OnClick handler at runtime(basically, I want this form to either edit or create a record, and Iwant to change the procedure it calls depending on what it should bedoing). However, apparently the .OnClick member is read only?
(Sample:)

<script language="jscri pt">
function do_edit() {
...
do_action_btn.T ext = "Save";
do_action_btn.O nClick = "do_update" ;
}
....
</script>
<html>
<head>
</head>
<body>
<form id="page_form" runat="server" />
...
<asp:Button id="do_action_b tn" runat="server" />
...
</form>
</body>
</html>

----------

Alternately, if the above isn't possible, I can do something withCommandButtons , but without a repeater/datagrid/datalist, I'm not surewhere to put the "OnItemComm and" property...

Thanks muchly,
Ricky Morse
.

Nov 18 '05 #2
submit/image buttons have a value they post back. just change the value in
client script, and check the value on the server side on the onclick event.
function do_edit() {
var btn = document.getEle mentById('do_ac tion_btn');
...
btn.value = "Save";
}

-- bruce (sqlwork.com)
"Richard Morse" <re*****@partne rs.org> wrote in message
news:re******** *************** ****@plato.harv ard.edu...
Hi! I have an aspx that I've created which has an asp:Button in it. I
would like to be able to change the OnClick handler at runtime
(basically, I want this form to either edit or create a record, and I
want to change the procedure it calls depending on what it should be
doing). However, apparently the .OnClick member is read only?

(Sample:)

<script language="jscri pt">
function do_edit() {
...
do_action_btn.T ext = "Save";
do_action_btn.O nClick = "do_update" ;
}
...
</script>
<html>
<head>
</head>
<body>
<form id="page_form" runat="server" />
...
<asp:Button id="do_action_b tn" runat="server" />
...
</form>
</body>
</html>

----------

Alternately, if the above isn't possible, I can do something with
CommandButtons, but without a repeater/datagrid/datalist, I'm not sure
where to put the "OnItemComm and" property...

Thanks muchly,
Ricky Morse

Nov 18 '05 #3

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

Similar topics

2
2114
by: giant food | last post by:
Hi, I'm writing an asp app. I have a text box with a validator and a submit button. Here is code from my .aspx file.... <asp:TextBox ID="txName" TextMode="SingleLine" Runat="server" /> <asp:RequiredFieldValidator ID="vName" Runat=server ControlToValidate="txName" /> <asp:Button ID="btnSave" CssClass="button" Runat="server" />
4
2277
by: z. f. | last post by:
Hi, I'm having an aspx page with a server form. i have a grid with a delete button and below the grid, another area with inputs for inserting new values and an "add" button for submiting the lower area of the form. on the lower area i have validators for validating input.
1
1488
by: tshad | last post by:
I want to be able to change the color of the text of a button after it is pressed. The first part of the event is: sub submitQuestion_click(Sender as Object, e as EventArgs) trace.warn("Sender text = " & Sender.text) trace.warn("Sender color = " & Sender.ForeColor.ToString()) Sender.ForeColor = System.Drawing.Color.Red
3
2458
by: wardy1975 | last post by:
Hi all....looking for a bit of help here....I'm using an asp.net server side button, and trying to add an onclick event on the button to call a javascript function. However, I am trying to enter the onclick syntax directly in the html instead of via the attributes.add functionality (this is required due to the dynamic nature of how the buttons are added to the screen). The problem is, I get a compilation error when I try to load the page...
0
7959
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
7883
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
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8021
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
8254
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
6677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5421
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
3876
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...
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.