Hi, i have formview control in my page and on that i have two textboxes and button in it which display at runtime. i declare the button event in my aspx.vb
Protected Sub insertbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then Exit Sub
' Determine the currently logged on user's UserId
Dim currentUser As MembershipUser = Membership.GetUser()
Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)
Dim connectionString As String = ConfigurationManager.ConnectionStrings("SecurityTutorialsConnectionString").ConnectionString
Dim insertSql As String = "INSERT INTO Reply(Subjects, Bodi, CommentDates UserId) VALUES(@Gameid, @Subjects, @Bodi, @CommentDates, @UserId)"
Using myConnection As New SqlConnection(connectionString)
myConnection.Open()
Dim myCommand As New SqlCommand(insertSql, myConnection)
myCommand.Parameters.AddWithValue("@Subject", subject1.Text.Trim())
myCommand.Parameters.AddWithValue("@message", message.Text.Trim())
myCommand.Parameters.AddWithValue("@CommentDates", DateTime.Now())
myCommand.Parameters.AddWithValue("@UserId", currentUserId)
myCommand.ExecuteNonQuery()
Label2.Text = "Your Comment has Been Added to our Database. Thank You"
myConnection.Close()
End Using
End Sub
and the button property
<asp:Button ID="Button1" runat="server" Text="post" CausesValidation="true" OnClick="insertbutton_Click" />
but when i click on button it shows the error like this.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'subject1' is not declared.
Source Error:
Line 39:
Line 40: Dim myCommand As New SqlCommand(insertSql, myConnection)
Line 41: myCommand.Parameters.AddWithValue("@Subject", subject1.Text.Trim())
Line 42: myCommand.Parameters.AddWithValue("@message", message.Text.Trim())
Line 43: myCommand.Parameters.AddWithValue("@CommentDates", DateTime.Now())
i place the following in my onload event
Dim drp As Label
drp = form1.FindControl("Label2")
Dim erp As TextBox
erp = form1.FindControl("subject1")
Dim crp As TextBox
crp = form1.FindControl("message")
but the object not handled at runtime.
Please help me to solve this.
Thank you