08.19.09
Javascript: To prevent or disable double click of button
Dim sb As New System.Text.StringBuilder()
sb.Append(“if (typeof(Page_ClientValidate) == ‘function’) { “)
sb.Append(“if (Page_ClientValidate() == false) { return false; }} “)
sb.Append(“this.value = ‘Please Wait…’;”)
sb.Append(“this.disabled = true;”)
sb.Append(Me.Page.GetPostBackEventReference(Me.btnSubmit))
sb.Append(“;”)
btnSubmit.Attributes.Add(“onclick”, sb.ToString())
08.24.08
Web.config – The entry ‘ ‘ has already been added error
If you happened to encounter this error, it may probably due to a duplicated copy of “web.config” exist in the parent folder which causes the IIS to read it twice. Verify that the parent folder does not have another copy of web.config file, and if yes, remove it. This was the issue arised and solved with the advised method.
10.26.05
Fully functional strong typed collections
If you’ve done OOP (Object Oriented Programming) in VB6, you’ve probably made instances of your custom-made classes. Maybe you even had a sort of grouping mechanism, a way for storing multiple instances of classes. That’s what this FAQ is about!
In my examples, I will use a Customer Class. This class is a basic data-class containing information about a specific customer.
There are several ways for keeping multiple instances :
- Array : easy to use
Drawbacks : pre-defined size, slow searching - Collection : fast searching, no pre-defined size, for-each loops, …
- Dictionary : same as Collection
One common drawback of these structures is that there is no control of the type of objects you store. For example, in a Collection you could add Customer-objects, but also (in the same collection object) some basic strings. This is bad, because most of the time you want only Customer-objects in your collection.
A way to overcome this problem is to encapsulate the collection in custom made collection class :
Code:
Public Property Get Item(Index As Integer) As Customer
Set Item = c.Item(Index)
End Property
But by doing this, you loose the for-each loop functionality of your collection.
Code:
For Each c In custColl
’Do Stuff
Next
The trick is to implement the NewEnum property in your collection Class. If you’ve added this property, you can use the for-each structure to loop trough your objects in your collection.
Code:
Set NewEnum = c.[_NewEnum]
End Property
Implementing this is only 1 step of the procedure to make it work. The next thing you have to do is setting the Procedure settings of the NewEnum property :
- Click ‘Tools’ menu -> ‘Procedure Attributes…’
- Select ‘NewEnum’ in the Name list
- Click the ‘Advanced>>>’ button
- And type ‘-4′ in the ‘Procedure ID’ combo. This item is not in the list, so you have to type it manually.
- Click ok
Now you have created a fully functional strong typed collection!! For a complete implementation and a test project, see my added VB project.
10.25.05
Object Oriented Approach – Business Objects
Business objects is often relates to programming objects. The mighty power of OOA is undeniable. I’m hoping to practice the OOA in developing business objects while doing my coding. An excerpt from Wikipedia on the definition of business object;
Business objects are objects in a computer program that abstract the entities in the domain that the program is written to represent. For example, an order entry program needs to work with concepts such as orders, line items, invoices and so on. Each of these may be represented by a business object. Good business objects will encapsulate all of the data and behavior associated with the entity that it represents. For example, an order object will have the sole responsibility for loading an order from a database, exposing or modifying any data associated with that order (i.e. order number, the order’s customer account), and saving the order back to the database.
Business objects don’t necessarily need to represent objects in an actual business (though they often do). They can represent any object related to the domain in which a developer is creating business logic for. The term is used to distinguish between the objects a developer is creating or using related to the domain and all the other types of object he or she may be working with such as user interface widgets and database objects such as tables or rows.
The concept of a business object is closely associated with the Component-based Scalable Logical Architecture (CSLA) developed by Rockford Lhotka.
Reference: Wikipedia
Scope of Class Members; Public, Private, Protected, Friend
Scope of a Class Members
Besides Private and Public, VB.NET introduces few new keywords. The following keywords are used to define scope of a class member.
Keyword
Scope
Private
Scope is limited to the defined class only.
Public
Object can be called from the outside of the class.
Friend
Scope is limited to the application in which class is defined.
Protected
Available to the class and it’s derived classes.
Protected Friend
Available to the class, the application, and the derived classes.
“Share” in classes – Visitors counter
In general, it is good practice to always explicitly define the scope of methods and variables to avoid confusion. As with shared methods, we can scope the shared variable as required. Where Shared methods are Public by default, Shared variables are Private by default.
Public Class MyCounter
Private Shared mintCount As Integer
Public Sub New()
mintCount += 1
End Sub
Public ReadOnly Property Count() As Integer
Get
Return mintCount
End Get
End Property
End Class
The above function can be used to calculate the numbers of visitors that visit your site.
To call it,
Dim obj As MyCounter
obj = New MyCounter()
And you get your own simple visitors counter!
10.24.05
WordPress’s ASP.NET Unofficial Blog
As an asp.net developer, i hope to share what i’ve learned and the experience i will be going through, throughout the way i’m developing my application. Feel free to post a comment, share your tips, ask your question, share your problem, and i’ll help in everyway possible. This is another blog, affiliate with infoct.net and linuxct.tk. If you would like to contribute in this blog, feel free to leave a comment. Will appreciate it very very much.
Warmest Regards,
EKLim
Hello world!
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!