Custom List Box Control with DblClick for Click and Double Click Events

clock August 11, 2008 13:05 by author administrator

kick it on DotNetKicks.com

Need a double click event for a list box? After searching around i couldn't find any decent vb.net methods so i decided to write one.

As always if you want to skip all the mumbo jumbo you can download the sample project and control here.  CustomControlListBox.zip (54.01 kb)

 

So how does the control work? When the control is rendered it adds a couple of attributes to the HTML listbox for click and ondblclick events.

writer.AddAttribute("ondblclick", Page.ClientScript.GetPostBackEventReference(Me, "dblclick"))

By implementing the IpostbackEventHandler for the class we're able to intercept the postback handler and look for the event argument, click and dblclick. 

Private Sub RaisePostBackEvent(ByVal eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent

        If eventArgument = "click" Then

            OnClick(EventArgs.Empty)

        End If

         If eventArgument = "dblclick" Then

            OnDblClick(EventArgs.Empty)

        End If

     End Sub

 

To get the double click even to work you'll need to ensure the autopostback is set to true and the ProcessDbouleClick is true also, you can always use the click event too. Yes the listbox has a selected index changed event, but what if the user clicks on the same list item? that event never get's fired so i added support for a click event also.

 How the control shows up on your toolbox menu. 

Complete Code Listing:

Imports System

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Text

Imports System.ComponentModel

 

<ToolboxData("<{0}:SimmonsListBox ProcessClick=False ProcessDoubleClick=False runat=server></{0}:SimmonsListBox>")> _

    Public Class SimmonsListBox

    Inherits System.Web.UI.WebControls.ListBox

    Implements IPostBackEventHandler

#Region "Properties"

 

 

    <DefaultValue(False)> _

    Public Property ProcessClick() As Boolean

        Get

            Dim o As Object = ViewState("ProcessClick")

 

            Return IIf((o Is Nothing), False, CBool(o))

        End Get

 

 

        Set(ByVal value As Boolean)

 

            ViewState("ProcessClick") = value

            If value = True Then

                ProcessDoubleClick = False

            End If

        End Set

    End Property

 

    <DefaultValue(False)> _

    Public Property ProcessDoubleClick() As Boolean

        Get

            Dim o As Object = ViewState("ProcessDoubleClick")

            Return IIf((o Is Nothing), False, CBool(o))

        End Get

        Set(ByVal value As Boolean)

            ViewState("ProcessDoubleClick") = value

            If value = True Then

                ProcessClick = False

            End If

        End Set

    End Property

 

 

#End Region

 

 

#Region "Event Handlers"

 

    Dim ClickEventKey As Object = New Object

    Dim DblClickEventKey As Object = New Object

 

    Public Event Click As EventHandler

    Public Event DblClick As EventHandler

 

    Protected Overridable Sub OnClick(ByVal e As EventArgs)

        RaiseEvent Click(Me, e)

    End Sub

 

    Protected Overridable Sub OnDblClick(ByVal e As EventArgs)

        RaiseEvent DblClick(Me, e)

    End Sub

 

 

#End Region

 

    Private Sub RaisePostBackEvent(ByVal eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent

        If eventArgument = "click" Then

            OnClick(EventArgs.Empty)

        End If

 

        If eventArgument = "dblclick" Then

            OnDblClick(EventArgs.Empty)

        End If

 

    End Sub

 

    Protected Overloads Overrides Sub AddAttributesToRender(ByVal writer As HtmlTextWriter)

        MyBase.AddAttributesToRender(writer)

 

 

        If ProcessClick Then

            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(Me, "click"))

        End If

 

        If ProcessDoubleClick Then

            writer.AddAttribute("ondblclick", Page.ClientScript.GetPostBackEventReference(Me, "dblclick"))

        End If

 

        MyBase.AddAttributesToRender(writer)

 

    End Sub

 

    Protected Overloads Overrides Sub RaisePostDataChangedEvent()

        MyBase.RaisePostDataChangedEvent()

    End Sub

 

End Class

 

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Creating a Custom Control Extending the power of Panel

clock August 4, 2008 17:57 by author administrator

In this article I will explain how to quickly and easily extend the power of the panel to create a nice looking container which you will soon be able to view at my Job Site

kick it on DotNetKicks.com

 

If you want to skip all the mumbo jumbo and download the example project then go here: CustomControl.zip (56.06 kb)

Now what's the result? What do you get out of developing a custom panel control? First you get to drag and drop reusable and modifiable UI Container elements. Now admittadly i could have really enabled support for multiple themes even true theme support but hey i'm just throwing this out there maybe you can extend it and send it back.

The kewl thing about a custom control is that it enables child controls ad design time a panel is especially useful as a custom control because we can put controls in it at design time.

 

This picture shows you how the control renders

This picture shows you  how it looks at design time.

 

 

 

 

Here is the main part of the code. On thing to keep in mind when developing custom controls is if you want to theme a custom control (not really done here) you need to add a registery assebler to the theme skin file.

 

<%@ Register Assembly="Simmons.Controls" Namespace="Simmons.Controls.CustomControls" TagPrefix="cc1" %>

 

 

This is the main part of the code.

 

 

Imports System

Imports System.Drawing

Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Text

Imports System.Web.UI

Imports System.Web.UI.HtmlControls

Imports System.Web.UI.WebControls

 

 

Namespace CustomControls

    <ToolboxData("<{0}:Container runat='server' HeaderText='Heading' HeaderWidth='300' ></{0}:RoundedContainer>")> _

    Public Class Container

        Inherits Panel

        Private _headerText As String

        Private _headerwidth As String

 

        Public Property HeaderText() As String

            Get

                Return _headerText

            End Get

            Set(ByVal value As String)

                _headerText = value

            End Set

        End Property

 

 

        <Category("HeaderStyle"), PersistenceMode(PersistenceMode.InnerProperty), Themeable(True)> _

        Public Property HeaderWidth() As String

            Get

                Return _headerwidth

            End Get

            Set(ByVal value As String)

                _headerwidth = value

            End Set

        End Property

 

 

        Protected Overloads Overrides Sub RenderChildren(ByVal writer As HtmlTextWriter)

 

            Dim strContainerWidth As String

            Dim strHeaderWidth As String

 

            strContainerWidth = _headerwidth + "px"

            strHeaderWidth = Convert.ToString(Convert.ToInt16(_headerwidth) - 22) + "px"

 

            ' FUll container

            writer.AddAttribute(HtmlTextWriterAttribute.[Class], "ContainerFull")

            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, strContainerWidth)

            writer.RenderBeginTag(HtmlTextWriterTag.Div)

 

            'header left

            writer.AddAttribute(HtmlTextWriterAttribute.[Class], "ContainerHeadLeft")

            writer.RenderBeginTag(HtmlTextWriterTag.Div)

            'header left

            writer.RenderEndTag()

 

            'header right

            writer.AddAttribute(HtmlTextWriterAttribute.[Class], "ContainerHeadRight")

            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, strHeaderWidth)

            writer.RenderBeginTag(HtmlTextWriterTag.Div)

            writer.AddAttribute(HtmlTextWriterAttribute.[Class], "ContainerHeadText")

            writer.RenderBeginTag(HtmlTextWriterTag.Div)

            writer.Write(_headerText)

            writer.RenderEndTag()

            'header right

            writer.RenderEndTag()

 

            ' Write Visual Contents

            writer.AddAttribute(HtmlTextWriterAttribute.[Class], "ContainerChildren")

 

            writer.RenderBeginTag(HtmlTextWriterTag.Div)

 

            writer.AddStyleAttribute(HtmlTextWriterStyle.Visibility, "hidden")

            writer.RenderBeginTag(HtmlTextWriterTag.Div)

            writer.Write("")

            writer.RenderEndTag()

 

            MyBase.RenderChildren(writer)

            writer.RenderEndTag()

 

            ' full container end

            writer.RenderEndTag()

 

        End Sub

        ' RenderChildren

 

 

    End Class

    ' class

End Namespace

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Adding an Icon to your webpage

clock August 2, 2008 17:43 by author administrator

Adding an Icon so it shows up in the web browser then just ad this code below to your page and create your icon file which points to the same location

 Make sure this goes in between the <head> on your webpage

<LINK REL="SHORTCUT ICON"
       HREF="~/FavIcon.ico" >

 One thing to point out is if you save the file just as FavIcon.ico then you don't need to put the above html markup into the  head. Typicaly you would use this approach if you want the icon to be displayed site wide.

 

 

kick it on DotNetKicks.com

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Visual Studio Performance

clock July 28, 2008 18:01 by author administrator

Is your visual Studio running like a dog? Have enough ram and your on a slick new CPU? Well the reason why it's slow might surprise you.

So most often than not i tell people to get as much ram as possible, a dual core processor is good a 64bit dual processor is ideal, Visual studio screams under a 64bit processor however if you don't have the ram and the hard drive then you won't be able to tell the difference.

Hard drive matters?

YES IT DOES. My laptop is allways chuging along because it's a dog of a 5400rpm hard drive, if you get a 7200rpm drive it'll make it faster a 10000 RPM drive will make things screem.

Ideally though you'll have two hard drives. one that your operating system runs on and one that you have Visual studio plugged into.

So make the most out of your visual studio and get the fastest hard drive you can.

  

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Versioning and Creating Branches in VSS Visual source safe 6.0

clock July 18, 2008 12:50 by author administrator

Firstly Microsoft has this backwords and not surprisingly why I had so many problems. If you've tried sharing and branching projects in VSS you might have experienced some of these problems.

1. the project is created underneath the project you just had.

2. a project cannot be shared under a descendant.

3. dragging and dropping a project somewhere else shares out all the files (yeah this one is annoying you have to select every file and branch it in every folder you can't do it recursively!) do not try this again! 

Well just ignore both of these problems and follow these simple steps to make your life easier.

 

How to branch a project in VSS version 6.0

 

Step 1.

Select the branch you want to copy the project to (this is what's backwards and unintuitive) right click then click share. 

 


Step 2.

Navigate to the project that you want to branch, make sure you have the branch check box checked in the bottom right hand corner, if you don't do this everything will be shared and you'll have to start again (unless you go and click every file and branch it!) Then click the Share button



Step 3.

 After you click the share button make sure recursive is checked or only the current folder will be moved over.

  

 

Step 4.

That's it, your project version has been branched.


kick it on DotNetKicks.com

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


how many megabytes in a gigabyte

clock July 16, 2008 23:59 by author administrator

There are 1024 megabytes in every gigabyte. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ASP.NET MVC CodePlex Preview 4 Installer + Source has just been release

clock July 16, 2008 19:27 by author administrator

 

 ASP.NET MVC CodePlex Preview 4 Installer + Source has just been release

 

http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=aspnet&ReleaseId=15389 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Interview Test for ASP.NET

clock July 16, 2008 13:23 by author administrator

Here's a simple test you can give candidates. 

 

You can download the same project here: DotNetTest.zip (13.94 kb)

.Net Test

Purpose: Evaluate candidate’s familiarity with OO Design and implementation.

 

Database

 

  1. Create a table in the database (connection string in Web.Config) Called Emails
    1. Emails table should have 4 columns. First column is called ID it’s a primary key with identity insert turned on.
    2. Other three columns should be called Email, Name, HasError has error should be of type bit.
  2. Put the SQL create table script into the App_Data folder
  3. Create a stored procedure that accepts three parameters Email,Name,HasError
  4. Using dynamic SQL within the stored procedure insert the record into the database.

 

Business Logic

 

  1. Implement ASM.Web.Business.Emailer.Insert should iterate through collection inserting records into the database via stored procedure implemented in Data section.
  2. Implement ASM.Web.Common.Email both shared Sub. This logic should email and call Emailer.Insert.

 

User Interface

  1. Create a web form.
  2. Put two text boxes on the page. One called Email the other name.
  3. Place two buttons on the page once called “Send Once” the other “Send 5 Times”
  4. Using javascript create validation that forces the user to enter text into both fields and alerts the user to enter in text use this when someone clicks on either buttons.
  5. Add a Custom Validator control to ensure the user enters a valid email address.
  6. When you click the Send Once button it should implement ASM.Web.Common.SendEmail using Business.Email Class
  7. When you click the Send 5 Times email it should implement the ASM.Web.Common.SendEmail using the Business.EmailCollection Class

 

Result:

 

When you click the Send Once button it send one email and insert one record into the Emails table.

 

When you click the Send 5 Times button it should send 5 emails and insert 5 records into the Emails table.

 


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Emailing using VB.NET and the system.net namespace

clock July 14, 2008 20:36 by author administrator

Emailing in VB.Net is a synch. But there are some things you should be aware of.

 1. always handle errors on the send, i've never seen an app that hasn't failed email at some point in time.

2. ensure you use the Imports system.net statement at the top of your page.

3. if everything completed successfully and you didn't recieve the email you might have relaying disabled. 

 

 Sub Authenticate()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is the body content of the email."
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
'to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = New NetworkCredential("username", "secret")
smtp.Send(mail)
End Sub 'Authenticate

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Welcome to VBDork.NET

clock July 14, 2008 20:35 by author administrator

As my first post on this blog i'd like to start off by stating that by no means do I claim supierer dorkyness to any other .NET developer out there.

Enjoy my blog and comment on what ou wish. 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5




Sign in