Update Fails-- not finding controls?

1 view
Skip to first unread message

TheWall

unread,
May 10, 2008, 8:32:33 PM5/10/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
A SQL connection on the aspx page fills the listbox. I click on a
name in the list box and on postback it fills the eight objects.

On click of btnUpdate the object are not found for the update. I have
tried form.findcontrol as you will notice commented out below as well
as various other solutions. I know that the update works because all
but these four get updated:

1. varTier = txtTier.Text
2. varWorkPhone2 = txtWorkPhone.Text
3. varHomePhone2 = txtHomePhone.Text
4. varMobilePhone2 = txtMobilePhone.Text


Any help would be much appreciated. I really need to complete this by
Monday.


Thank you and don't forget Mother's Day this Sunday,
TheWall




Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Data.Sql
Imports System.Data
Imports System.Web.Mail
Imports System.Web.Configuration
Imports System.Collections.CollectionBase

Partial Class CallTree
Inherits System.Web.UI.Page


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim connectionString As String =
System.Configuration.ConfigurationManager.ConnectionStrings("RCSConnectionString").ConnectionString
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim SQLstr As String
Dim varStaffName As String
'Dim varWorkPhone2 As String
'Dim varHomePhone2 As String
'Dim varMobilePhone2 As String
Dim dr As SqlDataReader
'Dim varVCNUmber As String
varStaffName = lbFullName.SelectedValue.ToString


'varWorkPhone2 = txtWorkPhone.Text
'varHomePhone2 = txtHomePhone.Text
'varMobilePhone2 = txtMobilePhone.Text

If Page.IsPostBack Then

SQLstr = " SELECT "
SQLstr = SQLstr & " ISNULL(StaffID,'') As StaffID,
ISNULL(RegNumber,'') AS RegNumber, "
SQLstr = SQLstr & " ISNULL(VCNumber,'') AS VCNumber,
ISNULL(Position,'') AS Position, "
SQLstr = SQLstr & " ISNULL(FullName,'') AS FullName,
ISNULL(Tier,0) AS Tier, ISNULL(WorkPhone,'') AS WorkPhone, "
SQLstr = SQLstr & " ISNULL(HomePhone,'') AS HomePhone,
ISNULL(MobilePhone,'') AS MobilePhone "
SQLstr = SQLstr & " FROM tblCallTree "
SQLstr = SQLstr & " WHERE FullName = '" & varStaffName &
"' "
'Response.Write(SQLstr)
myConnection = New
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("RCSConnectionString").ConnectionString)

myConnection.Open()

myCommand = New SqlCommand(SQLstr, myConnection)

dr = myCommand.ExecuteReader()
txtStaffID.Text = ""
lblRegNumber.Text = ""
lblVCNumber.Text = ""
lblPosition.Text = ""
lblFullName.Text = ""
txtTier.Text = ""
txtWorkPhone.Text = ""
txtHomePhone.Text = ""
txtMobilePhone.Text = ""



While dr.Read()
txtStaffID.Text = dr.GetString(0)
lblRegNumber.Text = dr.GetString(1)
lblVCNumber.Text = dr.GetString(2)
lblPosition.Text = dr.GetString(3)
lblFullName.Text = dr.GetString(4)
txtTier.Text = dr.GetValue(5)
txtWorkPhone.Text = dr.GetString(6)
txtHomePhone.Text = dr.GetString(7)
txtMobilePhone.Text = dr.GetString(8)

End While

dr.Close()
dr.Dispose()





myConnection.Close()
myConnection.Dispose()
End If

End Sub


Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click


Dim connectionString As String =
System.Configuration.ConfigurationManager.ConnectionStrings("RCSConnectionString").ConnectionString
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim SQLstr As String
Dim icount As Integer
Dim varTier As Integer
Dim varWorkPhone2 As String
Dim varHomePhone2 As String
Dim varMobilePhone2 As String
Dim varStaffID As String
Dim varCallingStaffID As String
'txtTier = form1.FindControl("txtTier")
'txtWorkPhone = form1.FindControl("txtWorkPhone")
'txtHomePhone = form1.FindControl("txtHomePhone")
'txtMobilePhone = form1.FindControl("txtMobilePhone")
'Dim varTier = form1.FindControl("txtTier")
'Dim varWorkPhone2 =
form1.FindControl("txtWorkPhone").ToString
'Dim varHomePhone2 =
form1.FindControl("txtHomePhone").ToString
'Dim varMobilePhone2 =
form1.FindControl("txtMobilePhone") .ToString

varTier = txtTier.Text
varWorkPhone2 = txtWorkPhone.Text
varHomePhone2 = txtHomePhone.Text
varMobilePhone2 = txtMobilePhone.Text
varStaffID = txtStaffID.Text
varCallingStaffID = "0999820227"


SQLstr = " UPDATE tblCallTree "
SQLstr = SQLstr & " SET Tier = '" & varTier & "', WorkPhone
= '" & varWorkPhone2 & "', "
SQLstr = SQLstr & " HomePhone = '" & varHomePhone2 & "',
MobilePhone = '" & varMobilePhone2 & "', "
SQLstr = SQLstr & " DataEntryDate = GetDate(), Completed =
1, CallingStaffID = '" & varCallingStaffID & "' "
SQLstr = SQLstr & " WHERE StaffID = '" & varStaffID & "' "
'Update will set Completed = True
myConnection = New
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("RCSConnectionString").ConnectionString)

Response.Write(SQLstr)


myConnection.Open()



'Get Identity
myCommand = New SqlCommand(SQLstr, myConnection)


icount = myCommand.ExecuteNonQuery


myConnection.Close()
myConnection.Dispose()


End Sub
End Class

Cerebrus

unread,
May 11, 2008, 12:51:13 PM5/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think you should be retrieving the references to the controls in the
DataBound event. It's possible they haven't been created when the
control enters your btnUpdate_Click event handler.
> System.Configuration.ConfigurationManager.ConnectionStrings("RCSConnectionS­tring").ConnectionString
> System.Configuration.ConfigurationManager.ConnectionStrings("RCSConnectionS­tring").ConnectionString

TheWall

unread,
May 11, 2008, 5:40:10 PM5/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
How does one reference these controls in a databound event? Can you
recommend a reference?
> > End Class- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages