ASP button order

liunx

Guest
Hey guys sorry for the barage of VB.NET questions, but im new to it...

I have a form with 2 buttons on it, one is a search button, one is a add button. I want the add button to be the default for the enter press. Becuase if a user presses the enter button when no data is in the searhc field then all hell breaks loose! any help?

I was told that there is an order you can specify in the .aspx page???use a required validator....

or a script that stops submitting if conditions are not met.Will do...

On another topic, rather than creating a new thread. I was wondering if you could help me with a problem that i should know but cant get to work...

Back to the old Employee classes and such, if there is a class member variable called mNumber which is simply a number that get incremented when a new employee is created. I am having trouble keeping the number unique to each employee that gets created.
(Note, this number is also shared with the sub-class of RestrictedEmployee, so if a RestrictedEmployee gets created the number increases again).

My testing is done like this:

create new employee (emp1)
emp1 number is 100000 as it should be
create new Restricted employee (rEmp2)
rEmp2 number is 100001 as it should be

but then if i do a simple toString() of the first employee again his number is now 100001 like the second employee...why???

also if i continue and create another employee (emp3) now all 3 employee numbers are 100002, how do keep them unique to each employee????

this is killing meCreate the variable as "static" or Shared in VB.net and Method.

in C# syntax would be.

class Employee
{
private long m_lngEmployeeId;
private static long m_lngNewEmployeeId = 0;

public Employee()
{
lngEmployeeId = GetNewEmployeeId();

}

public static long GetNewEmployeeId()
{
lngNewEmployeeId++;
return lngNewEmployeeId;
}
}

Create a property to get the employee Id back from the private variable.

The reason is that you are using "static" variables you must copy into non-static variables. As it would is accessing a "static" variable. in C/C++ it means the declared variable/method is static is only available to the current file. In C++ methods it means that the keyword "this" is not passed to the function. "this" is a pointer to the current object, it is hidden from the programmer, its done by the compiler. However static does not do this for you, methods are accessed just as C#/VB.net but variables that are static members can only be accessed by static methods.

What static means in this way is that all copies of the class will share the same static variables. No matter the thread. It makes values non-thread safe completely. No matter what thread modifies the variable it will be modified in each instance. To return the static value instead of reference to the variable fixes this.oh ok, i think i get ya, ill give it a try and let ya know how i go

Cheers!sorry, im not sure i get ya in the end...

here is a cut down version of my code:
(maybe i have a problem with my toString method??)



Public Class Employee
'Variable delcarations
Public mName As String
Protected mPin As String
Public Shared mNumber As Integer = 99999
Public mBuildings() As Integer
Public mDepartment As DeptType
Public mStartDate As Date
Public mExpiryDate As Date
Private mlastPin As String = ""

'Enumeration of departments
Enum DeptType
Finance = 1 ' Finance will be the default department
IT = 2
Maintenance = 3
Manufacturing = 4
Personnel = 5
End Enum

...
...HERE WERE SOME MORE PROPERTIES TAKEN OUT FOR NOW
...

'Employee number property
Public Shared ReadOnly Property number() As Integer
Get
Return Employee.mNumber
End Get
End Property

'Constructor
Public Sub New(ByVal name As String, _
ByVal department As DeptType, _
ByVal startDate As Date, _
ByVal pin As String, _
ByVal buildings As Integer())
'Call Super class New Method
MyBase.New()
...
... MORE CONSTRUCTOR STUFF
...
'increment Number
mNumber += 1
End Sub

'Function to format employee class to a readable output
Public Overrides Function ToString() As String
Dim s As String
Dim building As Integer
s += "Class : " & Me.GetType.Name & vbNewLine & _
"Employee Name : " & name & vbNewLine & _
"Employee Number : " & number & vbNewLine & _
"Department : " & department & vbNewLine & _
"Start Date : " & startDate & vbNewLine & _
"Expiry Date : " & expiryDate & vbNewLine & _
"Buildings : "
For Each building In mBuildings
s += building & " "
Next
Return s
End Function
End Class



hoep you can help...in the constructor you can see I call the static method internal to it, assign it to a member non-static variable.

That way it is unique and not static.

THe method that returns the unique id for each class is static along with the variable that is declated in the class scope. It increments it returns the value in the constructor, do not do it else when in the code.

Also you should place your "enum" in the namespace not the class scope. DO use namespace, do not let VS.net do it for you. As you will begin to understand the language and OOP more, this will also insure if you are not using VS.net that it will be compliant to use in C#. As VB.net allows for Global scope ie NO namespace but no other language can even see it.ok, it works now thanks so much! :D:D

but i dont wana seem like a dumb...you know what, but i just dont see why it works like that. Ive been coding for a while and i should get it, but i dont! I feel slow tonight!
 
Back
Top