first i hve created text boxes n in update i want to send the value of each text box in database
If Not IsPostBack Then
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 If
End Sub
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("Default")
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Dim PageContent As String
Dim id As Integer
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
'myTextBox.ID = ds.Tables(0).Rows(i).Item(0) Dim txt As TextBox = CType(Page.FindControl(id), TextBox)
PageContent = txt.Text.Trim
Dim success As Integer = GetInspired.UpdatePageText(id, PageContent)
Next
Dim txt As TextBox = CType(Page.FindControl(id), TextBox)
myTextBox.ID = ds.Tables(0).Rows(i).Item(0) i m defining id
which is 1004
error:
Server Error in '/' Application.
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.
Source Error:
Line 46: 'myTextBox.ID = ds.Tables(0).Rows(i).Item(0)
Line 47: Dim txt As TextBox = CType(FindControl(id), TextBox)
Line 48: PageContent = txt.Text.Trim Line 49: Dim success As Integer = GetInspired.UpdatePageText(id, PageContent)
Line 50:
for above code it show error
Dim str As String = objTextBox.Text
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.
Source Error:
Line 46: 'Content = Request.Form("ctl00_InnerContent_1004")
Line 47: Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id), TextBox)
Line 48: Dim str As String = objTextBox.Text Line 49: Dim success As Integer = GetInspired.UpdatePageText(id, str)
Line 50:
sriramabi has it right, you need to use a FindControl() method. If the textbox is in something like a table, you need to use the <tableName>.FindControl("controlName");
The key is knowing what the name of the control is. Or if it is in a table cell, you could use Table.Cells[#][#].Controls[#] to get that and cast it to your textbox.
So the id "1004" doesn't exist in the Request.Form collection. What keys do exist in it? Set a breakpoint in your submit event handler and find out how many keys are in there.
Smadhu
Member
509 Points
980 Posts
how to get value from dynamic created text box
Apr 04, 2012 01:49 PM|LINK
how to get value from dynamic created text box
first i hve created text boxes n in update i want to send the value of each text box in database
If Not IsPostBack Then
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 If
End Sub
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("Default")
Dim MeCount As Integer = ds.Tables(0).Rows.Count()
Dim PageContent As String
Dim id As Integer
For i = 0 To MeCount - 1
id = ds.Tables(0).Rows(i).Item(0)
'myTextBox.ID = ds.Tables(0).Rows(i).Item(0)
Dim txt As TextBox = CType(Page.FindControl(id), TextBox)
PageContent = txt.Text.Trim
Dim success As Integer = GetInspired.UpdatePageText(id, PageContent)
Next
Dim txt As TextBox = CType(Page.FindControl(id), TextBox)
it shows error
plz help
mm10
Contributor
6395 Points
1182 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:00 PM|LINK
Request.Form("IdOfTextBox"):
protected void Page_Load(object sender, EventArgs e)
{
TextBox txt = new TextBox();
txt.ID = "txtBox";
plc.Controls.Add(txt);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string value = Request.Form["txtBox"];
}
Smadhu
Member
509 Points
980 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:01 PM|LINK
no its not working
I have multiple textboxes
myTextBox.ID = ds.Tables(0).Rows(i).Item(0) i m defining id
which is 1004
error:
Server Error in '/' Application.
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.
Source Error:
Line 46: 'myTextBox.ID = ds.Tables(0).Rows(i).Item(0) Line 47: Dim txt As TextBox = CType(FindControl(id), TextBox) Line 48: PageContent = txt.Text.Trim Line 49: Dim success As Integer = GetInspired.UpdatePageText(id, PageContent) Line 50:mm10
Contributor
6395 Points
1182 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:05 PM|LINK
Make sure you use the correct client side id of the textbox, then it will work. What is the client side id of your textbox?
If you have multiple textboxes you get the values the same way for each one, i.e. Request.Form("clientsideid").
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:19 PM|LINK
hi
u can try this
id = ds.Tables(0).Rows(i).Item(0)
Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id ), TextBox)
Dim str As String = objTextBox.Text
thank u
mm10
Contributor
6395 Points
1182 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:24 PM|LINK
C#: string postedValue = Request.Form["1004"];
VB.NET: Dim postedValue As String = Request.Form("1004")
Smadhu
Member
509 Points
980 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:27 PM|LINK
soryry but
VB.NET: Dim postedValue As String = Request.Form("1004")
is not workng atall
Smadhu
Member
509 Points
980 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:29 PM|LINK
for above code it show error Dim str As String = objTextBox.Text 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. Source Error: Line 46: 'Content = Request.Form("ctl00_InnerContent_1004") Line 47: Dim objTextBox As TextBox = DirectCast(PageContentSection.FindControl(id), TextBox) Line 48: Dim str As String = objTextBox.Text Line 49: Dim success As Integer = GetInspired.UpdatePageText(id, str) Line 50:trekie86
Member
290 Points
76 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:33 PM|LINK
sriramabi has it right, you need to use a FindControl() method. If the textbox is in something like a table, you need to use the <tableName>.FindControl("controlName");
The key is knowing what the name of the control is. Or if it is in a table cell, you could use Table.Cells[#][#].Controls[#] to get that and cast it to your textbox.
mm10
Contributor
6395 Points
1182 Posts
Re: how to get value from dynamic created text box
Apr 04, 2012 02:35 PM|LINK
So the id "1004" doesn't exist in the Request.Form collection. What keys do exist in it? Set a breakpoint in your submit event handler and find out how many keys are in there.