Compiler Error Message:BC30451: Name 'txtevent_title' is not declared.
lblMessage2.Text = txtevent_title.text & " Submitted!"
The code seems right to me, I do not understand why. Take a look below in short and sweet codes:
<%@dotnet.itags.org. Page Language="VB" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<%@dotnet.itags.org. Import Namespace="System.Configuration" %>
<%@dotnet.itags.org. Import Namespace="System.Text"%>
<script runat="server">
Dim dsn As String = ConfigurationSettings.AppSettings("shift_dsn")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim myConnection As New SqlConnection(dsn)
Dim query AS String = "SELECTevent_title, event_excerpt, event_extended FROM tbl_event WHEREeventID=19" '& Request.QueryString("id")
Dim sqlAdapter As New SqlDataAdapter(query, myConnection)
Dim ds as new DataSet()
sqlAdapter.Fill(ds, "event")
dgrEvent.DataSource = ds.Tables("event")
dgrEvent.DataBind()
End If
End Sub
Public Sub Edit(Sender As Object, e As EventArgs)
lblMessage2.Text = txtevent_title.text & " Submitted!"
End Sub
</script>
<html>
<head>
<title>Test</title>
</head>
<body>
<form runat="server">
<div align="center">
<asp:label id="lblMessage2" runat="server" /><br />
<asp:Repeater id="dgrEvent" runat="server">
<ItemTemplate>
<p><strong>Event Name:</strong>
<asp:textbox runat="server" id="txtevent_title"name="txtevent_title" MaxLength="100" Columns="45" text='<%#Container.DataItem("event_title") %>' />
</p>
<p><strong>Excerpt:</strong><br />
<asp:TextBox id="event_excerpt" TextMode="MultiLine" rows="4"runat="server" columns="45" text='<%#Container.DataItem("event_excerpt") %>'></asp:TextBox>
</p>
<p><strong>Extended:</strong><br />
<asp:TextBox id="event_extended" TextMode="MultiLine" rows="7"runat="server" columns="45" text='<%#Container.DataItem("event_extended") %>'></asp:TextBox>
</p>
</ItemTemplate>
</asp:Repeater>
<p><asp:Button OnClick="Edit" Text="MakeChanges" runat="server" /> </p>
</div>
</form>
</body>
</html>
I suppose, the problem lies with this : txtevent_title.text
T should be capital in text... it should betxtevent_title.Text
Thanks/007
The problem still stands. Either txtevent_title.Text and txtevent_title.text is same.
daveynin wrote: The problem still stands. Either txtevent_title.Text and txtevent_title.text is same.
Yeah I guess vb.net is not case sensitive.
Anyway I guess the problem is the TextBox is not declared inside the code behind. For example, when you drag and drop a textbox from toolbox onto the designer, vs.net adds the following code inside the part that says "Web Form Designer Generated Code"
A Sample--
#Region " Web Form Designer Generated Code "
ProtectedWithEvents TextBox2As System.Web.UI.WebControls.TextBox
#EndRegion
Try removing thename attribute from the control's declaration.
I do not have VB.NET. I am doing hard code for ASP.NET.
However, I added "Web Form Designer Generated Code" code as shown above and I tested it: the problem changes, and it say:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 38: lblMessage2.Text = txtevent_title.Text & " Submitted!"
I can't figure this out, Anyone could help to solve this problem?
You do not need to add that code manually. If you read my previous post properly, I was saying VS.NET adds that code. You are not using vs.net and you are not using code behind, so you do not have to worry about it at all.
The problem in your case is, the textbox control is inside the Repeater control, so you can not access it directly
Try the following
ForEach rItemInMe.dgrEvent.Items
If rItem.ItemType = ListItemType.AlternatingItemOrElse rItem.ItemType = ListItemType.ItemThen
Dim testTxtBoxAsNew TextBox
testTxtBox=CType(rItem.FindControl("txtevent_title"), TextBox)
lblMessage2.Text = testTxtBox.text & " Submitted!"
EndIf
Next
Note that the above code I typed with hand and there could be several syntax errors. Anyway give it a try
0 comments:
Post a Comment