473,325 Members | 2,872 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,325 software developers and data experts.

Problem executing button-clicks using delegates (with example)

Hi!

This has been annoying me all day, and I can't get it to work It is really
driving me nuts!

Basicly this simple webapp created to illustrate my problem, renders five
buttons, and adds a handler to the click event. When a button is clicked,
the background-color is set to blue.

Try running the page, and clicking the "Do stuff and update controls
again"-button. Now click one of the test-buttons. Notice the click-event
does not fire, the button is not made blue. Click a test-button again, and
notice now the event is firing.

Now try clicking the "Do stuff and do NOT update controls"-button. Then
click the test-buttons. Notice how the events fire nicely!

I am sure this is not a bug, I think it is simply a matter of me not
understanding the flow of the page-events somehow, but I am stuck and would
really appreciate any help.

The demo-app in itself does not make sense, but I think it is the easiest
way to illustrate my problem. In my real-life app, the buttons are rendered
one for each row in an databasetable, and the buttons remove an item from
the databasetable on click. Therefore, when I click a button (testX in the
example) to remove an item, I need to re-render all the buttons, because one
of them has now been removed.

How do I make this work?

Thanks in advance

- Klaus

[aspx]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id="Form1" method="post" encType="multipart/form-data"
runat="server">
<P><asp:button id="Button1" runat="server" Text="Do Stuff and Show
Controls again"></asp:button>
<asp:Button id="Button2" runat="server" Text="Do Stuff and do not update
Controls"></asp:Button></P>
<P><asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder></P>
</form>
</body>
</HTML>
[/aspx]

[codebehind, vb]

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ShowMeTheButtons()
End Sub

Sub ShowMeTheButtons()
PlaceHolder1.Controls.Clear()
PlaceHolder1.Controls.Add(MakeFiveTestButtons)
End Sub

Function MakeFiveTestButtons() As PlaceHolder

Dim plc As New PlaceHolder
Dim btnTest As System.Web.UI.WebControls.Button
For i As Integer = 1 To 5
btnTest = New System.Web.UI.WebControls.Button
btnTest.Text = "Test" & i.ToString
btnTest.CommandArgument = i
AddHandler btnTest.Click, AddressOf TestButtonClick
plc.Controls.Add(btnTest)
Next

Return plc

End Function

Private Sub TestButtonClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim btn As System.Web.UI.WebControls.Button = CType(sender,
System.Web.UI.WebControls.Button)
btn.BackColor = System.Drawing.Color.Blue
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Do stuff here which affects the data, the buttons are generated
from in the real-life app
ShowMeTheButtons()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
'Do stuff here which affects the data, the buttons are generated
from in the real-life app
End Sub
[/codebehind, vb]


Nov 19 '05 #1
1 1779
"Klaus Jensen" <fo****@bout.it> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...

I have uploaded the Asp.Net project zipped to this url:

http://www.agilator.dk/temp/delegatetest.zip
Nov 19 '05 #2

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

Similar topics

2
by: (Pete Cresswell) | last post by:
I've been perusing a "real-life" application and notice that for instance, in a button's Click() event, they don't write the processing code. Instead, they raise an event like AddNewRecord and...
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0...
1
by: Yoshitha | last post by:
HI I am calling exe (vb.net application) from web application for this i wrote code like this system.diagnosis.process.start("e:\...") i wrote above code in button click event.
13
by: Jason Jacob | last post by:
To all, I have a GUI program (use c#), and I have create a Thread for loading some bulk data, I also arrange the GUI program like this: 1) load a form showing "Wait for loading..." etc 2) a...
5
by: msuk | last post by:
All, I have a ASP.NET webform that has a button that when clicked simply directs the user to another .htm page - code below private void btnSend_Click(object sender, System.EventArgs e) { ...
4
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
2
by: John Walker | last post by:
Hi, On my Webform my ASP:Button does not execute the Javascript code which is 'added' to it on the page load, and I'm trying to figure out why. Please take a look at my code and the error message...
2
by: Octopus0 | last post by:
hi, I have an application that connect to another server when the user press a button but the problem is that if the user clicked the button many times and error page " There are too many...
102
by: hug | last post by:
www.webmaster, was suggested that this ng could be a better place.] I've updated my test server to handle if-modified-since. I've noticed that the (old copies I run of) IE and Netscape seem...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.