CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 2/16/2005 9:24:21 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 44 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
CompiledMonkey
Asp.Net User
click events in custom control2/16/2005 9:24:21 PM

0/0

I've build a custom control that extends the panel control. After I've built my form from user input, I add a file TableRow with submit and reset buttons. Here is what that code looks like:


submitCell = New TableCell
Dim submitBtn As Button = New Button
submitBtn.GetType.GetEvent("Click").AddEventHandler(submitBtn, New EventHandler(AddressOf Me.Save))
submitBtn.Text = "Submit"
submitCell.Controls.Add(submitBtn)

tr.Cells.Add(submitCell)
t.Rows.Add(tr)


Everything renders fine on the screen. However, when I click the Submit button it doesn't execute the Save method I told it to run. Here's that method:


Public Sub Save(ByVal sender As Object, ByVal e As EventArgs)
System.Diagnostics.Debug.WriteLine("in save")
End Sub


Can anyone help me figure out why it's not calling that method when clicked?
Chris Stewart
http://www.compiledmonkey.com
puco_sk
Asp.Net User
Re: click events in custom control2/17/2005 9:56:59 AM

0/0

The button must be created before the postback is resolved. When the postback resolves and the button is not created you get an exception. You can recreate the button in OnInit phase.
Martin Pernecky



NetPublisher CMS
CompiledMonkey
Asp.Net User
Re: click events in custom control2/17/2005 7:17:43 PM

0/0

I see what you mean, but this worked before and I'm not sure why. I added the buttons in the OnInit method, but when I loop through the controls after a post back, the Table control that contains the dynamic textboxes doesn't exist anymore. For the same reason you mentioned above I guess. Is there a way to disable the post back when I click submit so I can get the texboxes and their values?
Chris Stewart
http://www.compiledmonkey.com
CompiledMonkey
Asp.Net User
Re: click events in custom control2/17/2005 8:40:02 PM

0/0

Ok, I?ve discovered some things on this topic today.

Below is the source file for the user control....

If I call the GenerateForm method in the Page_Load of a client web application, the form builds properly and clicking the Save button displays the ID and value of each textbox on the form. In our business process, you have to narrow down your selection with 2 drop downs. I guess through the two post backs on the client web application, something happens with the user control. It still renders the form dynamically and loads the correct controls, but clicking the Save button makes the form go away (i.e., blows up) with no error message. I imagine there is an issue with the view state somewhere, but I?m really not sure where to start. The actual user control code itself works fine. Any ideas?


Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace DynamicForm

<DefaultProperty("Text"), ToolboxData("<{0}:Form runat=server></{0}:Form>")> Public Class Form
Inherits System.Web.UI.WebControls.Panel

#Region "Variables"

Private _text As String

#End Region

#Region "Properties"

<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

#End Region

#Region "Methods"

Public Sub GenerateForm(ByVal accomplishmentCode As String)

Try

Dim ac As BusinessLogic.Collections.AttributeCollection = BusinessLogic.Data.Attribute.GetAttributes(accomplishmentCode)

' check to make sure there are attributes to add
If ac.Count <> 0 Then

Dim t As Table = New Table
t.BorderStyle = BorderStyle.Dashed
Dim tr As TableRow

' loop through AttributeCollection and build html
' from it
For Each a As BusinessLogic.Data.Attribute In ac

tr = New TableRow
tr.BorderStyle = BorderStyle.Solid
Dim displayLabelCell As TableCell
Dim inputCell As TableCell

' add display label to page
displayLabelCell = New TableCell
Dim displayLabel As Label = New Label
displayLabel.Text = a.Name
displayLabelCell.Controls.Add(displayLabel)

' add input control to page
Select Case a.ControlType()

Case "TextBox"
inputCell = New TableCell

Dim tb As TextBox = New TextBox
tb.ID = a.AttributeId
tb.Width = Unit.Parse(a.Width.ToString())
tb.Height = Unit.Parse("22")
inputCell.Controls.Add(tb)

End Select

tr.Cells.Add(displayLabelCell)
tr.Cells.Add(inputCell)
t.Rows.Add(tr)

Next

' add buttons for submit and reset
tr = New TableRow
Dim submitCell As TableCell
Dim resetCell As TableCell

submitCell = New TableCell
Dim submitBtn As Button = New Button
submitBtn.ID = "SubmitButton"
submitBtn.Text = "Submit"
submitBtn.GetType.GetEvent("Click").AddEventHandler(submitBtn, New EventHandler(AddressOf Me.SaveForm))
submitCell.Controls.Add(submitBtn)

resetCell = New TableCell
Dim resetBtn As Button = New Button
resetBtn.ID = "ResetButton"
resetBtn.Text = "Reset"
resetBtn.GetType.GetEvent("Click").AddEventHandler(resetBtn, New EventHandler(AddressOf Me.ResetForm))
resetCell.Controls.Add(resetBtn)

tr.Cells.Add(submitCell)
tr.Cells.Add(resetCell)
t.Rows.Add(tr)

Me.Controls.Add(t)

Else
Me.Text = "No attributes to load"
End If

Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Exception in Form.GenerateForm(): " & ex.ToString())
End Try

End Sub

Public Sub SaveForm(ByVal sender As Object, ByVal e As EventArgs)

System.Diagnostics.Debug.WriteLine("in save")

Try

' rip out table control
Dim t As Table
t = Me.Controls(0) ' should only be one control in the container

For Each r As TableRow In t.Rows

For Each cell As TableCell In r.Cells
For Each c As Control In cell.Controls

If TypeOf c Is TextBox Then
Dim textBox As TextBox
textBox = c
System.Diagnostics.Debug.WriteLine("ID: " & textBox.ID & vbTab & "Value: " & textBox.Text)
End If

Next
Next

Next

Catch ex As Exception
System.Diagnostics.Debug.WriteLine("Exception in Form.Save(): " & ex.ToString())
End Try

End Sub

#End Region

End Class

End Namespace

Chris Stewart
http://www.compiledmonkey.com
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
.NET Windows Forms Custom Controls: Forms Custom Controls Authors: Richard L. Weeks, Pages: 288, Published: 2002
Pro .NET 2.0 Windows Forms and Custom Controls in C#: From Professional to Expert Authors: Matthew MacDonald, Pages: 1037, Published: 2005
Pro ASP.NET 2.0 in VB 2005: special edition. Authors: Laurence Moroney, Matthew MacDonald, Pages: 1360, Published: 2006
Visual Basic 2005 Programmer's Reference Authors: Rod Stephens, Pages: 1022, Published: 2005
Professional Web Parts and Custom Controls with ASP.NET 2.0 Authors: Peter Vogel, Pages: 449, Published: 2005
Beginning Visual Basic 2005 Authors: Thearon Willis, Bryan Newsome, Pages: 799, Published: 2006
Excel 2003 VBA Programming with XML and ASP Authors: Julitta Korol, Pages: 948, Published: 2006
Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005 Authors: Matthew MacDonald, Pages: 1036, Published: 2006
Effective GUI Test Automation: Developing an Automated GUI Testing Tool Authors: Kanglin Li, Mengqi Wu, Pages: 445, Published: 2004

Web:
Wicked Code: Craft Custom Controls for Silverlight 2 The best way to learn about Silverlight 2 custom controls is to build ..... Traditional button controls only fire Click events if button-up events are ...
CodeProject: Managing ViewState, Rendering and Events in Composite ... Creating child controls, rendering, wiring up events, and managing viewstate when building an advanced custom server control that embeds other server ...
Exposing Events in Custom Silverlight Controls Sep 19, 2008 ... Exposing Events in Custom Silverlight Controls .... Again we will rely on intellisense to wire-up the click event to an event handler. ...
InformIT: Events and Properties for Composite Custom Controls in C ... Events and Properties for Composite Custom Controls in C#Builder ... Because the Click event of the AuthorBio control is public, it will appear on the ...
user custom controls in C# visual basic 2005, asp.net, application using user controls and creating custom user controls in c# visual basic ... Click on the validate button to see the result. 7. Writing Events to a control. ...
Microsoft ASP.NET QuickStarts Tutorial The RaisePostBackEvent method allows the control to handle the event, and to raise other events. Additionally, the ASP.NET page framework has a custom event ...
ASP.NET 2.0 - Handling events in custom control Jul 20, 2008 ... Handling events in custom control I have created a custom control to get the ... custom control.cs Code: ( text ) [DefaultEvent("Click")] ...
Writing C# Custom Events | O'Reilly Media Learn how to write custom events in C# using the Observer design pattern. ... called MyEvent for your custom control named MyControl that extends System. ...
Adding events to custom controls - TechSpace - Express Computer India We can also add properties and events to a custom control. .... As a result, whenever we drag our control on the form and double-click on the control in the ...
Help for Lotus Notes 8 (basic configuration) - Adding a custom ... Tip If you are a designer, you can modify the behavior of the control by changing its events using LotusScript. For example, you can modify the Click event ...

Videos:
Luke DuBois & Manrico Montero @ CUSTOM CONTROL part 2 Luke DuBois & Manrico Montero @ CUSTOM CONTROL, Heffner Alumni House, EMPAC @ R.P.I. / Troy, New .York. 26th October 2007 Curated by Kathleen Forde...
Luke DuBois & Manrico Montero @ CUSTOM CONTROL part 3 Luke DuBois & Manrico Montero @ CUSTOM CONTROL, Heffner Alumni House, EMPAC @ R.P.I. / Troy, New .York. 26th October 2007 Curated by Kathleen Forde...
Access 2000 Dev Level 11 The Access 2000 Dev Level 11 is part of KeyStone Learning Systems library of more than 1,200 CD-ROM and video-based information technology course tit...
Sue Costabile & Laetitia Sonami @ CUSTOM CONTROL, EMPAC Sue Costabile & Laetitia Sonami @ CUSTOM CONTROL, EMPAC, Heffner Alumni House, EMPAC @ R.P.I. / Troy, N.Y., October 26th 2007 Curated by Kathleen Fo...
Access 2000 Dev Level 11 The Access 2000 Dev Level 11 is part of KeyStone Learning Systems library of more than 1,200 CD-ROM and video-based information technology course tit...
Benton-C Bainbridge & Bobby Previte @ CUSTOM CONTROL, EMPAC Bobby Previte & Benton-C Bainbridge @ CUSTOM CONTROL, Heffner Alumni House, EMPAC @ R.P.I. / Troy, N.Y., October 26th 2007 Curated by Kathleen Forde...
Access 2000 Dev Level 11 The Access 2000 Dev Level 11 is part of KeyStone Learning Systems library of more than 1,200 CD-ROM and video-based information technology course tit...
Luke DuBois & Manrico Montero @ CUSTOM CONTROL, EMPAC Luke DuBois & Manrico Montero @ CUSTOM CONTROL, Heffner Alumni House, EMPAC @ R.P.I. / Troy, N.Y. 26th October 2007 Curated by Kathleen Forde http...
Access 2000 Dev Level 11 The Access 2000 Dev Level 11 is part of KeyStone Learning Systems library of more than 1,200 CD-ROM and video-based information technology course tit...
MIDI control data env + LIVE The extensive MIDI control features of Ableton Live 6 can be even further augmented by using Max/MSP as a filter and data trigger and manipulator. ...




Search This Site:










simple(?) question about derived controls

question re interfaces

validationsummary not displayign error message for a composite server control

servervariables object in a server control

composite control design-time properties

problem with treeview of asp.net 2.0

clarification needed for spla hosting of windows terminal services

anyone extended adrotator for multiple keywords?

derived class with new eventhandler, and it doesn't fire!

instantiation of custom control inside compiled codebehind

hopefully someone can help me

why is inamingcontainer not an attribute?

hosting for learning and working

hosting for asp.net + mql

adding a one-time client script from a control

migrate linux users

ipostbackdatahandler

why is runat=server required?

building and retrieving dynamic control values

user control type

get free hosting on iis7 with database on maximum asp

custom checkbox server control and checkedchanged event

how to set font style for a textbox in a composite control??!?

custom image control that renders showmodaldialog()

referencing a custom control that's not in a library

.net web application project error

how to host an asp.net 2.0 website on 2003 server iis 6.0

making my controls work like microsofts

asp.net hosting suggestions

how a icon can represent my custom control ?

  Privacy | Contact Us
All Times Are GMT