For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
Response.Write(id)
Dim LastTextBoxId As String = " Txt-" & id
id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0)
Content = Request.Form("id2")
above code is returning only id not the text inside the text box
i m getting only ID
but in request .form we hav to pass id or the name???
my textbox generated id at run time is ctl00_InnerContent_1004,so i tired to add dat also but its coming null
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
Dim PageNam As String = Request.QueryString("PageName")
Dim ds As DataSet = GetInspired.GetPageContent(PageNam)
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Dim success As Integer
Dim Content, id2 As String
Dim id As Integer
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
Response.Write(id)
Dim LastTextBoxId As String = " Txt-" & id id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0)
Content = Request.Form("id2")
Dim TempTextBox As TextBox = CType(TextBoxControlPlaceHolder.FindControl("ctl00_InnerContent_" & id2), TextBox)
Response.Write(TempTextBox)
Response.Write(Content)
'success = GetInspired.UpdatePageText(id, Content)
Next
If success Then
ErrorDisplay.Text = "Updated Successfully"
MultiView1.SetActiveView(View2)
End If
End Sub
Try to remove the If Not Postback check from the page load event:
MultiView1.SetActiveView(View1)
Dim PageNam As String = Request.QueryString("PageName")
PageId.Value = PageNam
Dim ds As DataSet = GetInspired.GetPageContent(PageNam)
' Dim ds As DataSet = GetInspired.GetPageContent("Default")
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Response.Write(MeCount)
For i = 0 To MeCount - 1
Dim myLabel = New Label
myLabel.ID = "lbl" & i + 1
myLabel.Text = "Content For " & ds.Tables(0).Rows(i).Item(2)
myLabel.CssClass = "lbl_sec"
Dim myTextBox = New TextBox
myTextBox.ID = ds.Tables(0).Rows(i).Item(0)
Dim LastTextBoxId As String = myTextBox.ID
myTextBox.CssClass = "Text_Sec"
myTextBox.TextMode = TextBoxMode.MultiLine
PageContentSection.Controls.Add(HtmlHelper.GetLiteral("<div id=Txt-" & LastTextBoxId & " >"))
Me.PageContentSection.Controls.Add(myLabel)
Me.PageContentSection.Controls.Add(myTextBox)
myTextBox.Text = ds.Tables(0).Rows(i).Item(3)
PageContentSection.Controls.Add(HtmlHelper.GetLiteral("</div>"))
Next
End Sub
If not postback i m only creating textboxes but in update i want text from textbox to submit to databse
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
Dim PageNam As String = Request.QueryString("PageName")
Dim ds As DataSet = GetInspired.GetPageContent(PageNam)
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Dim success As Integer
Dim Content, id2 As String
Dim id As Integer
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
Dim LastTextBoxId As String = " Txt-" & id
id2 = "ctl00_InnerContent_" & id
' Response.Write(id2)
'Content = Request.Form("id2")
Dim TempTextBox As TextBox = CType(TextBoxControlPlaceHolder.FindControl("id2"), TextBox)
Response.Write(TempTextBox)
'Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id2), TextBox)
'Content = TempTextBox.Text
'Response.Write(Content)
'success = GetInspired.UpdatePageText(id, Content)
Next
If success Then
ErrorDisplay.Text = "Updated Successfully"
MultiView1.SetActiveView(View2)
End If
End Sub
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:29 PM|LINK
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
Response.Write(id)
Dim LastTextBoxId As String = " Txt-" & id
id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0)
Content = Request.Form("id2")
above code is returning only id not the text inside the text box
i m getting only ID
but in request .form we hav to pass id or the name???
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:35 PM|LINK
with request.form i m pasing id ......of text box but it still not shwing me the content of the textbox
tarunSaini
Contributor
2948 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:37 PM|LINK
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textbox.aspx
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:47 PM|LINK
hi
u like check this
http://www.c-sharpcorner.com/uploadfile/kaunainbaig/creating-dynamic-textbox-and-get-its-value/
http://weblogs.asp.net/ksamaschke/archive/2003/04/27/6098.aspx
http://stackoverflow.com/questions/6411074/getting-value-from-dynamically-created-textbox-and-checkbox
http://www.dreamincode.net/forums/topic/201113-how-to-get-valus-in-dynamic-added-textbox/
thank u
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:50 PM|LINK
its still showing null value ????
my textbox generated id at run time is ctl00_InnerContent_1004,so i tired to add dat also but its coming null
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
Dim PageNam As String = Request.QueryString("PageName")
Dim ds As DataSet = GetInspired.GetPageContent(PageNam)
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Dim success As Integer
Dim Content, id2 As String
Dim id As Integer
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
Response.Write(id)
Dim LastTextBoxId As String = " Txt-" & id
id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0)
Content = Request.Form("id2")
Dim TempTextBox As TextBox = CType(TextBoxControlPlaceHolder.FindControl("ctl00_InnerContent_" & id2), TextBox)
Response.Write(TempTextBox)
Response.Write(Content)
'success = GetInspired.UpdatePageText(id, Content)
Next
If success Then
ErrorDisplay.Text = "Updated Successfully"
MultiView1.SetActiveView(View2)
End If
End Sub
mm10
Contributor
6399 Points
1184 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 04:05 PM|LINK
Try to remove the If Not Postback check from the page load event:
MultiView1.SetActiveView(View1) Dim PageNam As String = Request.QueryString("PageName") PageId.Value = PageNam Dim ds As DataSet = GetInspired.GetPageContent(PageNam) ' Dim ds As DataSet = GetInspired.GetPageContent("Default") Dim MeCount As Integer = ds.Tables(0).Rows.Count() Response.Write(MeCount) For i = 0 To MeCount - 1 Dim myLabel = New Label myLabel.ID = "lbl" & i + 1 myLabel.Text = "Content For " & ds.Tables(0).Rows(i).Item(2) myLabel.CssClass = "lbl_sec" Dim myTextBox = New TextBox myTextBox.ID = ds.Tables(0).Rows(i).Item(0) Dim LastTextBoxId As String = myTextBox.ID myTextBox.CssClass = "Text_Sec" myTextBox.TextMode = TextBoxMode.MultiLine PageContentSection.Controls.Add(HtmlHelper.GetLiteral("<div id=Txt-" & LastTextBoxId & " >")) Me.PageContentSection.Controls.Add(myLabel) Me.PageContentSection.Controls.Add(myTextBox) myTextBox.Text = ds.Tables(0).Rows(i).Item(3) PageContentSection.Controls.Add(HtmlHelper.GetLiteral("</div>")) Next End SubSmadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 04:09 PM|LINK
If not postback i m only creating textboxes but in update i want text from textbox to submit to databse
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
Dim PageNam As String = Request.QueryString("PageName")
Dim ds As DataSet = GetInspired.GetPageContent(PageNam)
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Dim success As Integer
Dim Content, id2 As String
Dim id As Integer
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
Dim LastTextBoxId As String = " Txt-" & id
id2 = "ctl00_InnerContent_" & id
' Response.Write(id2)
'Content = Request.Form("id2")
Dim TempTextBox As TextBox = CType(TextBoxControlPlaceHolder.FindControl("id2"), TextBox)
Response.Write(TempTextBox)
'Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id2), TextBox)
'Content = TempTextBox.Text
'Response.Write(Content)
'success = GetInspired.UpdatePageText(id, Content)
Next
If success Then
ErrorDisplay.Text = "Updated Successfully"
MultiView1.SetActiveView(View2)
End If
End Sub
mm10
Contributor
6399 Points
1184 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 04:13 PM|LINK
Yes, but you need to re-create the textboxes on every postback.
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 04:20 PM|LINK
i removed post back but still it shows me......null reference
i think u point is valid its something connected to the post back
mm10
Contributor
6399 Points
1184 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 04:47 PM|LINK
When using FindControl, you have to use the server side id: