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)
id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0)
' Dim myControl1 As Control = FindControl(id)
Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id2), TextBox)
Content = objTextBox.Text
Response.Write(Content)
success = GetInspired.UpdatePageText(id, Content)
Next
If success Then
ErrorDisplay.Text = "Updated Successfully"
MultiView1.SetActiveView(View2)
End If
End Sub
this id value is return correct textbox id for u r PageContentSection inner textbox..pls check.And pls putt correct textbox id in finecontrol value
id ..
Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id
), TextBox) Dim str As String = objTextBox.Text
If the item is in a table that is dynamically generated, you need to use the <TableName>.FindControl(id)
You need to go down to the lowest level to find the control. If the table name is dynamic, you'll need to do multiple find controls to get down to the textbox.
Dim t = (Table)Page.FindControl(<tableName>)
Dim tBox = t.FindControl(id)
If I've helped you, please mark my post as an Answer. Thanks.
You won't find the dynamically created control itself by the FindControl method as it is not preserved between postbacks. But you can find the VALUE of the dynamicallt created TextBox, that is the text in it, in the Request.Form collection.
If you loop through the Request.Form collection, you will find the value, i.e. the text, in the textbox:
for (int i = 0; i < Request.Form.Keys.Count; ++i)
{
Response.Write(Request.Form[i]);
}
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:50 PM|LINK
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) id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0) ' Dim myControl1 As Control = FindControl(id) Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id2), TextBox) Content = objTextBox.Text Response.Write(Content) success = GetInspired.UpdatePageText(id, Content) Next If success Then ErrorDisplay.Text = "Updated Successfully" MultiView1.SetActiveView(View2) End If End SubIts still not working
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:51 PM|LINK
hi
id = ds.Tables(0).Rows(i).Item(0)
this id value is return correct textbox id for u r PageContentSection inner textbox..pls check.And pls putt correct textbox id in finecontrol value id ..
Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id ), TextBox)
Dim str As String = objTextBox.Text
thank u
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:54 PM|LINK
i m putting corect id
but i really dont knw wht the prb is????
Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id ), TextBox)
Dim str As String = objTextBox.Text
showing 1 error
Object reference not set to an instance of an object.
i dont knw y,now i m using id=ctl00_InnerContent_1004
still its not showing ne thing
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:56 PM|LINK
hi
i think id2 = "ctl00_InnerContent_" & ds.Tables(0).Rows(i).Item(0)
is return correct textbox id in u r PageContentSection textbox id..pls check
trekie86
Member
290 Points
76 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:57 PM|LINK
If the item is in a table that is dynamically generated, you need to use the <TableName>.FindControl(id)
You need to go down to the lowest level to find the control. If the table name is dynamic, you'll need to do multiple find controls to get down to the textbox.
Dim t = (Table)Page.FindControl(<tableName>)
Dim tBox = t.FindControl(id)
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:59 PM|LINK
k ..
PageContentSection it is pannel?...
first u add dynamic textboxes in one pannel u r design page...
then use fine control...(my way)..
thank u
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:00 PM|LINK
PageContentSection is div
<div id="PageContentSection" runat="server">
</div>
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:02 PM|LINK
ya its is inside PageContentSection div
so do i hav to change path as its inside PageContentSection div
in my div PageContentSection
i m again creating a div
myTextBox.TextMode = TextBoxMode.MultiLine
PageContentSection.Controls.Add(HtmlHelper.GetLiteral("<div id=Txt-" & LastTextBoxId & "class='Section' >"))
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>"))
Smadhu
Member
510 Points
985 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:10 PM|LINK
plz do help me guys
mm10
Contributor
6395 Points
1182 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 03:17 PM|LINK
You won't find the dynamically created control itself by the FindControl method as it is not preserved between postbacks. But you can find the VALUE of the dynamicallt created TextBox, that is the text in it, in the Request.Form collection.
If you loop through the Request.Form collection, you will find the value, i.e. the text, in the textbox:
for (int i = 0; i < Request.Form.Keys.Count; ++i)
{
Response.Write(Request.Form[i]);
}