Daily Adventures

Monday, October 01, 2007

Dynamically set the focus of a control inside an update panel

I needed to hide and show panel inside an updatepanel. When one panel was hidden and the other one is shown, I needed the defaultbutton attribute to be updated and have the focus be on the button in the newly visible panel:

You can set these programatically by using this code:

Page.Form.DefaultFocus = btnConfirm.ClientID; //could be a text box
Page.Form.DefaultButton = btnConfirm.UniqueID;


The real trick is to get the Scriptmanager to update set the focus on the contol for you:
ScriptManager1.SetFocus(btnConfirm);

I tried having the form put the focus on the control but it didin't seem to work.
The above code does the trick.

Labels:

Tuesday, April 05, 2005

BUG: Error Message: Error '80004005' Unexpected Error

BUG: Error Message: Error '80004005' Unexpected Error

What a pain in my keister, Meister!!!
Man, talk about no help and no clue why my .aspx page would work about 5 times and then just get this horrible error. It happens when the ,net page tries to open a database connection.

Here's my (now obviusoly wrong code)

Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\Ctest\db\store.MDB"
Dim myConnection As OleDbConnection = New OleDbConnection(myConnectionString)

Dim myCommand As OleDbCommand
Dim myCommand2 As OleDbCommand
Dim myCommand3 As OleDbCommand
Dim result As OleDbDataReader
Dim result2 As OleDbDataReader
Dim result3 As OleDbDataReader

Dim mySelect As String = "Select subgroupsingroups.subgroupname,subgroupsingroups.idsubgroupsingroups from subgroupsingroups where idSubGroupsinGroups in(select idsubgroup from productsinsubgroup where idproduct=" & catid & ")"


myConnection.Open()

'Create an OleDbCommand object.
'Notice that we pass in the SQL statement and the OleDbConnection object.
myCommand = New OleDbCommand
myCommand.Connection = myConnection
myCommand.CommandText = mySelect


result = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

myRepeater.DataSource = result
myRepeater.DataBind()

Dim mySelect2 As String = "SELECT group_title, idgroup FROM allgroups ORDER BY idgroup"
myCommand2 = New OleDbCommand
myCommand2.Connection = myConnection
myCommand2.CommandText = mySelect2
myConnection.Open()
category1.DataValueField = "idgroup"
category1.DataTextField = "group_title"
result2 = myCommand2.ExecuteReader(CommandBehavior.CloseConnection)
category1.DataSource = result2
category1.DataBind()
objConnection.Close()

Dim mySelect3 As String = "SELECT [Partnumber] FROM Products1 where idProduct=" & catid
Dim mySelect4 As String = "SELECT [Title] FROM Products1 where idProduct=" & catid
myCommand3 = New OleDbCommand
myCommand3.Connection = myConnection
myCommand3.CommandText = mySelect3
myConnection.Open()
pronum = myCommand3.ExecuteScalar
myCommand3.CommandText = mySelect4
pronum2 = myCommand3.ExecuteScalar
objConnection.Close()

Label1.Text = pronum
Label2.Text = pronum2

Well, When I copy and paste code from somewhere, I need to be more careful and double check it, but because it is opening a connection and then not closing it (its closing the wrong connection), it give the Error '80004005' Unexpected Error, so I corrected the code:



Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\Ctest\db\store.MDB"
Dim myConnection As OleDbConnection = New OleDbConnection(myConnectionString)
Dim myConnection2 As OleDbConnection = New OleDbConnection(myConnectionString)
Dim myConnection3 As OleDbConnection = New OleDbConnection(myConnectionString)

Dim myCommand As OleDbCommand
Dim myCommand2 As OleDbCommand
Dim myCommand3 As OleDbCommand
Dim result As OleDbDataReader
Dim result2 As OleDbDataReader
Dim result3 As OleDbDataReader

Dim mySelect As String = "Select subgroupsingroups.subgroupname,subgroupsingroups.idsubgroupsingroups from subgroupsingroups where idSubGroupsinGroups in(select idsubgroup from productsinsubgroup where idproduct=" & catid & ")"


myConnection.Open()

'Create an OleDbCommand object.
'Notice that we pass in the SQL statement and the OleDbConnection object.
myCommand = New OleDbCommand
myCommand.Connection = myConnection
myCommand.CommandText = mySelect


result = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

myRepeater.DataSource = result
myRepeater.DataBind()

Dim mySelect2 As String = "SELECT group_title, idgroup FROM allgroups ORDER BY idgroup"
myCommand2 = New OleDbCommand
myCommand2.Connection = myConnection2
myCommand2.CommandText = mySelect2
myConnection2.Open()
category1.DataValueField = "idgroup"
category1.DataTextField = "group_title"
result2 = myCommand2.ExecuteReader(CommandBehavior.CloseConnection)
category1.DataSource = result2
category1.DataBind()
myConnection2.Close()

Dim mySelect3 As String = "SELECT [Partnumber] FROM Products1 where idProduct=" & catid
Dim mySelect4 As String = "SELECT [Title] FROM Products1 where idProduct=" & catid
myCommand3 = New OleDbCommand
myCommand3.Connection = myConnection3
myCommand3.CommandText = mySelect3
myConnection3.Open()
pronum = myCommand3.ExecuteScalar
myConnection3.Close()


myCommand.CommandText = mySelect4
myConnection.Open()
pronum2 = myCommand.ExecuteScalar
myConnection.Close()

Label1.Text = pronum
Label2.Text = pronum2


Works like a charm!!!
It would be nice if Microsoft could give a little more to go on!!

Wednesday, February 02, 2005

ImageButton Not working!!!

Nefarious ImageButton

I had this happen to me as well. I had installed SQL server 2000 Yesterday and I am not sure if this is the cause or not. The other possible culprit
was the new visual studio 2005 beta edition. I unstalled the VS beta edition first. Then I unistalled the .net framework (in the Add/Remove programs area) and then reinstalled the .net 1.1 framework.

Now everything works like a charm. Hope this helps someone.

Wednesday, November 24, 2004

Syringe Pumps -The "Genie"

Syringe Pumps -The "Genie"

This seems like a pretty cool syringe pump. Simple and easy to use. Price is right to. In my other searches I have found pumps @$1000 t0 $2000. Some fancy, some not, but this seems like it will do the trick.

Tuesday, November 23, 2004

First Blog Post...........

So many weird things happen at work with the VB.net projects I work on, that I thought it would be a good idea to post up some of the obscure problems I run into and their solutions. This way others can find them and solve them. I ran into 2 today.

Vb.net Error:
Unable to build dialog module named XXX

I got a whole bunch of these errors today when I went to rebuild a project. It turned out that my picture was missing.(the one I made for the setup screen)

Solution: Click on the deployment project and then choose the user interface menu. Click on the suspect menu (Start, Installation folder, etc..) and view properties. Under the BannerBitmap property, change it to none for now and rebuild. This solved my problem. I went back after I confirmed this was the problem and added the picture back in and re-assigned the new picture to the BannerBitmap properties. Everything works well now.


Vb.net Error:
could not load a type. Failed to partial bind xxx
This error comes at a weird point in my program if I do something 3 times in a row. After a little Google search, I've found out that this is caused when some appliaction path is updated. I reinstalled a new version of my program over an old one. That may be the problem.

Solution: Simply reboot the machine and this error goes away.