標題聽起來很簡單,但這裏是具體的。將值插入到sql server:控件未聲明
我被交給一箇舊的網站擴大一點。這是一個VB.NET實現,並且它是原始編碼器的第一個站點 - 所以有很多attaboys讓它工作。
總結網站:
母版頁設計,oAuth登錄頁面。主頁面是記錄的分頁,並根據用戶是否已登錄,顯示單獨的按鈕進行編輯。到目前爲止 - 沒有什麼大不了的,它很有效,都很好。
現在,當我們深入編輯頁面時,產品負責人希望能夠將記錄添加到記錄中。看起來很容易,除了實際插入之外,所有其他CRUD都已完成。
我在頁面底部添加了一個textarea,並且有一個按鈕。插入事件正在運行,虛擬記錄正在放入數據庫中。
但是,當我嘗試獲取textarea的值,並將其放入查詢時失敗。
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="VB" runat="server" >
Protected Sub NewNoteButton_Click(sender As Object, e As System.EventArgs)
' Dim myStringResult As String = NewNoteTextArea.InnerHtml
MsgBox("Here1")
Dim constr As String = ConfigurationManager.ConnectionStrings("XXXXXConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("INSERT INTO EasementNote ([RE_Number], [noteuser], [note]) VALUES (@RE_Number, @NoteUser, @Note)")
cmd.Parameters.AddWithValue("@RE_Number", "test")
cmd.Parameters.AddWithValue("@NoteUser", "test")
cmd.Parameters.AddWithValue("@Note", "more testing")
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
MsgBox("here2")
End Sub
</script>
<head runat="server">
<title></title>
</head>
這裏就是我的HTML代碼
<asp:TableFooterRow Width="100%">
<asp:TableCell HorizontalAlign="center" ColumnSpan="2">
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</asp:TableCell>
<asp:TableCell HorizontalAlign="center" ColumnSpan="1">
<asp:TextBox id="NewNoteTextArea" TextMode="multiline" Columns="40" Rows="3" runat="server" />
<asp:Button runat="server" ID="NewNoteButton" Text="Insert Note" OnClick="NewNoteButton_Click"/>
</asp:TableCell>
</asp:TableFooterRow>
當我試圖抓住textarea的價值,我收到一個
甚感爲難爲什麼我收到此錯誤消息。順便說一句 - 頁面背後沒有代碼...不知道爲什麼,但沒有,但是當我添加一個,並將按鈕單擊事件移動到它時,按鈕單擊無法解決。
感謝您的期待。
在服務器控件內不應該使用FindControl引用,例如在這種情況下http://forums.asp.net/post/4479665.aspx – haraman
FindControl也會因'未聲明'錯誤而失敗。 – pithhelmet
看着你的代碼和評論,似乎你的TextBox是在一個Table(服務器控件)中,而Table又是在FormView中。如果是這樣,那麼你將不得不遵循相同的層次使用FindControl,如FormView> Table> FooterRow> Cell> TextBox在上面給出的asp.net論壇鏈接(檢查多個FindControl) – haraman