TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vivek Kumar Vishwas
NA
115
56.1k
How to access dynamically created Textbox ID in asp.net c#
Nov 8 2017 11:50 PM
Hello Friends !,
How to access dynamically created textbox value or id to save into database.
Textbox is creating dynamically successfully. Now what I want suppose I fill the text and when I press button to save that value into database table. How do I get that textbox id.
Below what i tried to do please check and resolve this problem soon.
aspx-----------
<
%@ Page
Language
=
"C#"
AutoEventWireup
=
"true"
CodeFile
=
"Dynamic-TextBox.aspx.cs"
Inherits
=
"Dynamic_TextBox"
%
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
>
</
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
>
</
asp:PlaceHolder
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
>
</
asp:Label
>
<
asp:Button
ID
=
"addnewtext"
runat
=
"server"
Text
=
"Add"
onclick
=
"addnewtext_Click"
width
=
"76px"
/>
<
asp:Button
ID
=
"btn_Save"
runat
=
"server"
Text
=
"Save Value"
onclick
=
"btn_Save_Click"
/>
</
div
>
</
form
>
</
body
>
</
html
>
.cs--------
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
Dynamic_TextBox : System.Web.UI.Page
{
static
Random random =
new
Random();
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
TextBox tb;
static
int
i = 0;
protected
void
addnewtext_Click(
object
sender, EventArgs e)
{
i++;
for
(
int
j = 0; j <= i; j++)
{
GenerateRandomNumber();
tb =
new
TextBox();
tb.ID = j.ToString();
PlaceHolder1.Controls.Add(tb);
}
}
public
void
GenerateRandomNumber()
{
for
(
int
i = 0; i < 2; i++)
{
Label1.Text =
"The generated Random number is "
+ (Convert.ToString(random.Next(10, 200)));
// to specify range for random number
}
}
protected
void
btn_Save_Click(
object
sender, EventArgs e)
{
}
}
Reply
Answers (
3
)
Connecting and using database
Run time error generated