ポストバック後にプレースホルダー内のコントロールの値を取得するにはどうすればよいですか?
背景情報
動的に作成された 2 つのコントロールがあります (それらはプレースホルダーの中にあります)。フォーム送信ボタンも動的に作成されました。明確にするために、ボタンが押された後に動的に作成されたフィールドの値を取得したいと考えています。
問題
request.form を使用すると、null 値が取得され続けます。ClientIDMode を静的にしようとしましたが、問題は解決しません。また、単純に PLACEHOLDER1.FindControll メソッドを使用しようとしましたが、これも null を返します
CODE(コントロールの値を取得しようとしているところ)
Protected Sub submitEdit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles submitEdit.Click
Dim currentClass As String = submitEdit.CssClass
If currentClass = "hidden active" Then
'Get Rid of Controls
EditHeaderH1.Visible = False
submitEdit.Visible = False
submitEdit.CssClass = "hidden inactive"
currentStatus.value = "updated"
''''''''''''''''''''''''''''''''''''''''
'Find subject and Post Content''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim subjectText As String = Request.Form("editSubject")
Dim editorText As String = Request.Form("editEditor")
Dim editID As String = Request.Form("hiddenID")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim connStr As String = ConfigurationManager.ConnectionStrings("oakfratnewsConnectionString").ConnectionString
Dim nCon As New SqlConnection(connStr)
Dim addCon As New SqlConnection(connStr)
Dim addCom As New SqlCommand("UPDATE News SET Subject = @Subject, [Content] = @Content WHERE (ID = @ID)", addCon)
addCom.Parameters.AddWithValue("@Content", Server.HtmlDecode(editorText))
addCom.Parameters.AddWithValue("@Subject", subjectText)
addCom.Parameters.AddWithValue("@ID", editID)
Try
addCon.Open()
addCom.ExecuteNonQuery()
addCon.Close()
Catch ex As Exception
End Try
End If
End Sub
コード: 最初に作成されたフィールド
Public Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "editPost" Then
plcEditor.Controls.Clear()
GridView1.Visible = False
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(index)
Dim ID As String = GridView1.Rows(index).Cells(0).Text
''''''''''''''''''''''''''''''''''''''''CREATE Controls for Placeholder
Dim editEditor As New CuteEditor.Editor
Dim hiddenID As New HiddenField
Dim subjectTXT As New TextBox
Dim br As New Literal
hiddenID.Value = ID
hiddenID.ID = "hiddenID"
editEditor.ID = "editEditor"
editEditor.ClientIDMode = ClientIDMode.Static
subjectTXT.ID = "editSubject"
subjectTXT.ClientIDMode = ClientIDMode.Static
hiddenID.ClientIDMode = ClientIDMode.Static
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim i As Integer = 100
Dim editButton As New Button
editButton.ID = String.Concat("editButton-", i)
editButton.CommandArgument = i.ToString
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim sbjLabel As New Label
sbjLabel.Text = "Subject: "
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
editEditor.AutoConfigure = CuteEditor.AutoConfigure.Simple
br.Text = "<br/><br/>"
plcEditor.Controls.Add(hiddenID)
plcEditor.Controls.Add(sbjLabel)
plcEditor.Controls.Add(subjectTXT)
subjectTXT.Width = "100"
subjectTXT.Height = "25"
subjectTXT.CssClass = "editInput"
plcEditor.Controls.Add(br)
plcEditor.Controls.Add(br)
plcEditor.Controls.Add(editEditor)
plcEditor.Controls.Add(br)
plcEditor.Controls.Add(br)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim connStr As String = ConfigurationManager.ConnectionStrings("oakfratnewsConnectionString").ConnectionString
Dim nCon As New SqlConnection(connStr)
Dim addCon As New SqlConnection(connStr)
Dim addCom As New SqlCommand("SELECT * FROM [News] WHERE ([ID] = @ID)", addCon)
addCom.Parameters.AddWithValue("@ID", ID)
Dim results As SqlDataReader
addCon.Open()
results = addCom.ExecuteReader
While results.Read()
Dim editText As String = results.Item("Content")
Dim Subject As String = results.Item("Subject")
EditHeaderH1.InnerText = "Edit Post - " & Subject
editEditor.Text = editText
subjectTXT.Text = Subject
End While
results.Close()
addCon.Close()
''BUTTON Fade-IN Effect''
submitEdit.CssClass = "hidden active"
End If