Creating a Custom List View
Creating a Custom List View
Creating a Custom List View
Creating a Custom List View
Creating a Custom List View
Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View
Creating a Custom List View Creating a Custom List View
Creating a Custom List View
Go Back  Xtreme Visual Basic Talk > > > Creating a Custom List View


Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2008, 08:11 PM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default Creating a Custom List View


I'm trying to create a custom list view box that will display a list of items with corresponding images associated with these items. Likewise, when the user clicks on an item within the list view, the server will respond accordingly.

Sounds pretty nice, huh? Well, so far I can do ALL of this BUT, the "OnClick" event. So, in order to move forward, I need to consult outside help.

Currently, on page load, the page adds custom controls that are populated with the icon and text. I'd like to add the handling of the click event at this adding stage. But, my custom control doesn't fire a click event. How can I create events on a custom control? Can someone point me into that direction?

Thanks to all for their help.
Reply With Quote
  #2  
Old 05-07-2008, 01:05 PM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default

I have found so far...

Within the Server Control...
Code:
    Public Event Click As EventHandler

    Protected Sub OnClick(ByVal e As EventArgs)
        RaiseEvent Click(Me, e)
    End Sub

    Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
        OnClick(System.EventArgs.Empty)
    End Sub
I can then add to the page creating the server control...
Code:
AddHandler TrialLink.Click, AddressOf ListViewItem_Click
SO, everything seems to be tied together nicely. But I'm not getting that server control to fire the click event.

Any thoughts??
Reply With Quote
  #3  
Old 05-07-2008, 07:16 PM
MKoslof's Avatar
MKoslofCreating a Custom List View MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Are you trying to raise an event through the RaisePostBackEvent? What exactly is your goal, typically you wouldn't want to do this, nor would this fire.... Is this user driven or an event you want to fire automatically based on some condition?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #4  
Old 05-08-2008, 03:25 PM
Spico Spico is offline
Newcomer
 
Join Date: May 2008
Posts: 1
Default

did you used with events on the declaration?
Reply With Quote
  #5  
Old 05-09-2008, 11:56 AM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default

MKoslof and Spico,

Thank you both for your responses.

MKoslof,
My goal is to create a "List View" by populating a web-container with custom controls. This custom control is just a line of HTML that displays an image and the associated text with a hidden value. "On mouse-click" of this custom control, I'd like the server to handle the hidden value appropriately. To answer your questions, yes, I'm trying to raise the event through RaisePostBackEvent, I have the code displayed of what I'm using. Also, this is a user driven event I'm trying to create... OnClick. Any suggestions?

Spico,
I have never seen "with events" before... Where do I place this line? I just tried googling it and I've gotten a list of bogus sites. Can you reccommend a good page to learn more about this?
Reply With Quote
  #6  
Old 05-09-2008, 12:12 PM
MKoslof's Avatar
MKoslofCreating a Custom List View MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK I get the generic concept. I understand.

Yes, as Spico is specifying to you, you need to have the control ADDED to your target page/control peppered with the WithEvents property.

Here is a good example for you, let me know if you have any additional questions after reading, I'll most likely be able to answer them

http://www.ondotnet.com/pub/a/dotnet...x1.html?page=4
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #7  
Old 05-09-2008, 04:29 PM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default

MKoslof,

Thanks for your post. I've read the article, plus did some more research on the topic and I'm still not getting the click event to fire. I've decided to take this down to ground zero and build it back up. It would be great if you could continue to help guide me in this process.

SO, ground zero... What am I missing here?
I have a custom control that has ONE input... Text. By specifying the text, a <div> statement gets generate and spits out <div>Input Text</div>. I want this div statement to have a click event that posts back to the server.

The render code...
Code:
    Public Overrides Sub RenderBeginTag(ByVal ControlWriter As System.Web.UI.HtmlTextWriter)
        ControlWriter.Write("<div>" & Me.Text())
    End Sub

    Public Overrides Sub RenderEndTag(ByVal ControlWriter As System.Web.UI.HtmlTextWriter)
        ControlWriter.Write("</div>")
    End Sub

From the recent readings, I've gathered that my click event needs to be declared and coded as follows...
Code:
    Private Shared ReadOnly ClickHandler As New Object()

    Public Custom Event OnClick As EventHandler
        AddHandler(ByVal value As EventHandler)
            Events.AddHandler(ClickHandler, value)
        End AddHandler

        RemoveHandler(ByVal value As EventHandler)
            Events.RemoveHandler(ClickHandler, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim submitHandler As EventHandler = CType(Events(ClickHandler), EventHandler)
            If Not IsNothing(submitHandler) Then
                submitHandler(Me, e)
            End If
        End RaiseEvent
    End Event
I'm assuming, in the generation of the page, the server will automatically code in the post back event for the server to handle. Because I haven't added anything else. Or, should I not??

The page_Load code...
Code:
        TrialLink = New ListViewItem()
        TrialLink.Text = "Trial Link"
        AddHandler TrialLink.OnClick, AddressOf ListViewItem_Click

        ContainerStorage.Controls.Add(TrialLink)
And as you have guessed it... The OnClick doesn't fire. Or atleast, there is no post back to the server. So, what am I missing here?

Thanks again for all your help.
Reply With Quote
  #8  
Old 05-09-2008, 05:12 PM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default

By adding an onclick even within the <div> creation, I got it to work...
Code:
        outputHTML.Append("<div")
        outputHTML.Append(" id=""" & Me.ClientID & """")
        outputHTML.Append(" name=""" & Me.ClientID & """")
        outputHTML.Append(" onclick=""" & Page.ClientScript.GetPostBackClientHyperlink(Me, String.Empty) & ";""")
        outputHTML.Append(" style=""cursor: pointer;"">")
        outputHTML.Append(Me.Text())
I find this method extremely cheating and it totally by-passes the entire "click event" I've been striving to achieve. Or... Maybe this is just a short-hand way of doing it?? I'm not sure. BUT, I'd love to get someone's feed back about this.
Thanks!
Reply With Quote
  #9  
Old 05-09-2008, 07:55 PM
MKoslof's Avatar
MKoslofCreating a Custom List View MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

That is a round about way of doing it though client side events, basically something needs to invoke the actual post back still....for example, lets say its a button:

Code:
   Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
        RaiseEvent OnClick(eventArgument)
    End Sub

    Private Sub AddControls(theArg)
        Dim link As New Button
        link.Text = "Something"
        link.Attributes.Add("OnClick", Page.GetPostBackEventReference(Me, theArg)
    End Sub
Basically you need to invoke the actual postback and pass the GetPostbackReference your type instance (Me) and the eventArg/ID of the control

Look here as well.....

http://msdn.microsoft.com/en-us/libr...ce(VS.71).aspx
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #10  
Old 05-09-2008, 10:38 PM
DoughBoy DoughBoy is offline
Centurion
 
Join Date: Jun 2006
Posts: 196
Default

MKoslof,

Thanks for all your help in solving this.
Reply With Quote
  #11  
Old 05-10-2008, 03:48 PM
MKoslof's Avatar
MKoslofCreating a Custom List View MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No worries, always glad to help . Good luck
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Creating a Custom List View
Creating a Custom List View
Creating a Custom List View Creating a Custom List View
Creating a Custom List View
Creating a Custom List View
Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View Creating a Custom List View
Creating a Custom List View
Creating a Custom List View
 
Creating a Custom List View
Creating a Custom List View
 
-->