asp.net


how to get value from dynamically created textbox in asp.net


hi i'm Cannot get value dynamically created textbox and save into database. plz help
his is code which I have created in this code text box are created but when I will input the value in the text and retrieve the value from dynamically created text box it give error
protected void btnAtt_Click(object sender, EventArgs e)
{
int DPLID = int.Parse(DPLCategory.Text);
var query = (from p in database.tbl_Attributes
where p.ProductTypeId_FK == DPLID
select new
{
p.Attribute_Id,
p.AttributeName,
p.ProductTypeId_FK,
}).ToArray();
for (int i = 0; i < query.Count(); i++)
{
Label lblatt = new Label();
lblatt.ID = query[i].AttributeName;
lblatt.Text = query[i].AttributeName + " : ";
lblatt.CssClass = "control-label";
TextBox txtatt = new TextBox();
txtatt.ID = "txtatt"+i;
txtatt.Attributes.Add("runat", "server");
txtatt.Text = String.Empty;
txtatt.CssClass = "form-control input-sm";
HtmlTextWriterTag.Br.ToString();
Place1.Controls.Add(lblatt);
HtmlTextWriterTag.Br.ToString();
Place1.Controls.Add(txtatt);
HtmlTextWriterTag.Br.ToString();
}
}
protected void lbtnSave_Click(object sender, EventArgs e)
{
int DPLID = int.Parse(DPLCategory.Text);
var query = (from p in database.tbl_Attributes
where p.ProductTypeId_FK == DPLID
select new
{
p.Attribute_Id,
p.AttributeName,
p.ProductTypeId_FK,
}).ToArray();
int LastId = database.tbl_Products.Max(p => p.ProductId);
for (int i = 0; i < query.Count(); i++)
{
database.tbl_ProductValue.Add(new Models.tbl_ProductValue()
{
ProductId_FK = LastId,
AttributeID_FK = query[i].Attribute_Id,
ProductValue = ??,
});
database.SaveChanges();
}
}
plz help me for how to get textbox?
I haven't worked with WebForms in a while but you can access the controls by their IDs like this:
ProductValue = ((TextBox)FindControl("txtatt" + i)).Text;

Related Links

This page has redirect loop in asp.net error
Binding data to a hyperlink repeater - how can I control the Text attribute value of each hyperlink?
.net routing: Possible to restrict route to a certain domain?
AjaxFileUpload server events not firing
sql server timeout when executed via web service trough stored procedure
gridview: table-layout: fixed but with different width for columns
ASP.NET Access to path '\\xxxx' is denied
WIX - Conditionally install SQL Server and / or IIS if features chosen (Database + WebSite)
How to check the logged user info?
Is there a way to create a custom User and Role without specifying the TKey on IdenitityUser, IdentityRole, and IdentityDbContext?
Server looking for vb source file - Why?
disable session for static resources in asp.net
Make a property deserializable but not serializable
Assigning different website user roles - asp.net IDENTITY
Editable DropdownList in ASP.Net MVC4 razor view [_Duplicate]
ASP.net, how to make my dropdownlist

Categories

HOME
google-cloud-pubsub
teradata
process
openacc
packet
gap-system
ebay-api
stdout
x509certificate
localhost
osx-yosemite
token
ethereum
velocity
aspectj
websharper
sha1
css-float
ibatis
md2
google-street-view
passbook
formulas
ejb-3.1
klipfolio
beaker-notebook
bootstrap-accordion
struts
pydub
utc
stack-trace
boosting
uibarbuttonitem
jms-topic
r-factor
ios-autolayout
urhosharp
node-soap
webmock
odp.net
ragel
oracle-bpm-suite
queryover
cowboy
server-side-swift
google-cloud-powershell
flask-socketio
wink
playframework-1.x
webmatrix
totalview
tsc
pyautogui
vertex-shader
jira-agile
vitamio
camellia
bbedit
android-progressbar
dynamics-nav-2013
edgar
windows-phone-8-emulator
genome
skview
veeam
strcpy
numerical-recipes
douglas-peucker
qxorm
xcode5
fedena
novell
famous-engine
ccmenuitem
mvcgrid
traceur
imaplib
thucydides
cocotron
junction-table
reference-manual
biztalk-deployment
rbm
yii-components
volatility
hypertable
ios6-maps
winrt-async
bindinglist
django-1.4
towerjs
datejs
rjs
xpolog
cryptolicensing
virtual-destructor
user-preferences
ironpython-studio

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App