(I don’t understand ‘tyring to insert/update data’, ‘webcontrol is not associated with it’s property’!) // if you write code using parametrized query as paramxxx.value = textbox1 it’ll show above error to resolve it it should be paramxxx.value =textbox1.text
//This kind of error message can occur when you are trying to insert/update data or any kind of operation which involves textbox/dropdownlist The issue occurs if the webcontrol is not associated with its property
May be you have not associated the appropriate property of the control i.e textBox1.Text or dropdownlist1.SelectedItem.Value
<asp:TextBoxid='txtNumber'Runat='server' /><asp:RegularExpressionValidatorID='vldNumber'ControlToValidate='txtNumber'Display='Dynamic'ErrorMessage='Not a number'ValidationExpression='(^([0-9]*|\d*\d{1}?\d*)$)'Runat='server'></asp:RegularExpressionValidator>
<scriptlang='javascript'>functionCheckFunction()
{
if (document.getElementById(’<%=textbox2.ClientID%>’).value == '')
{
alert('Please enter a value');
return;
}
}
</script><asp:textboxid='textbox2'runat='Server'></asp:textbox><inputtype=buttonid='btn1'onclick='javascript:CheckFunction();'value='Click'>
’Populate the DataSet
’...
’Display in TextBoxes using Column Name
TextBox1.Text = ds.Tables (0).Rows(0)('ProductId').ToString ();
TextBox2.Text =ds.Tables (0).Rows(0)('ProductName').ToString ();
’Display in TextBoxes using Column Index
TextBox1.Text = ds.Tables (0).Rows(0)(0).ToString ();
TextBox2.Text =ds.Tables (0).Rows(0)(1).ToString ();
C#
//Populate the DataSet
//...
//Display in TextBoxes using Column Name
TextBox1.Text = ds.Tables [0].Rows[0]['ProductId'].ToString ();
TextBox2.Text =ds.Tables [0].Rows[0]['ProductName'].ToString ();
//Display in TextBoxes using Column Index
TextBox1.Text = ds.Tables [0].Rows[0][0].ToString ();
TextBox2.Text =ds.Tables [0].Rows[0][1].ToString ();
Id : <asp:TextBoxid='TextBox1'style='Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 32px'runat='server'></asp:TextBox>
Name : <asp:TextBoxid='TextBox2'style='Z-INDEX: 103; LEFT: 128px; POSITION: absolute; TOP: 72px'runat='server'></asp:TextBox>
VB.NET
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
’ Put user code to initialize the page here
Try
cn = New SqlConnection('server=localhost;uid=sa;pwd=;database=northwind')
cmd = New SqlCommand('select * from Products where productid =1', cn)
cn.Open()
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
rdr.Read()
TextBox1.Text = rdr('ProductId').ToString()
TextBox2.Text = rdr('ProductName').ToString()
Catch ex AsException
Response.Write(ex.Message.ToString())
Finally
rdr.Close()
cn.Close()
End Try
End Sub
C#
SqlConnection cn ;
SqlCommand cmd ;
SqlDataReader rdr ;
privatevoidPage_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page heretry
{
cn = new SqlConnection('server=localhost;uid=sa;pwd=;database=northwind');
cmd = new SqlCommand( 'select * from Products where productid=1 ', cn);
cn.Open();
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection );
rdr.Read ();
TextBox1.Text =rdr['ProductId'].ToString ();
TextBox2.Text =rdr['ProductName'].ToString ();
}
catch (Exception ex)
{
Response.Write (ex.Message.ToString ());
}
finally
{
rdr.Close();
cn.Close();
}
}
Dim textboxes(5) As TextBox
Dim i As Integer
For i = 0 To 4
textboxes(i) = New TextBox()
textboxes(i).ID = 'TextBox' + i
textboxes(i).AutoPostBack = True
PlaceHolder1.Controls.Add(textboxes(i))
Next
C#
TextBox[] textboxes = new TextBox[5];
for (int i=0; i<5; i++)
{
textboxes[i] = new TextBox();
textboxes[i].ID = 'TextBox' + i;
textboxes[i].AutoPostBack = true;
PlaceHolder1.Controls.Add(textboxes[i]);
}