Shepwedd
asked on
How do I change control attributes in C# asp.net?
I have written a C# website using visual studio 2008. I am using the asp.net 3.5 listview control as a frontend for my backend sql server 2005 database. I am having difficulty trying to reference the right event in the listview for disabling one of the controls in my insertitemtemplate. What I want is my textbox control in this template to become disabled when a certain value is selected from my dropdownlist. I thought it would be the itemdatabound event but when the value is selected in my dropdownlist the textbox is still enabled. Is it because I am using update panels that the page isn't getting refreshed upon selecting different dropdown choices? I tried AutoPostBack="true" but that did nothing also?
ASKER
I have written the attached within my item databound event but I get the "object reference not set to an instance of an object" error on the below line?
if (ddlFrequency.SelectedValu e == "5")
if (ddlFrequency.SelectedValu
DropDownList ddlFrequency = (DropDownList)lvPayments.FindControl("FrequencyEditDDL");
TextBox textBoxStopDate = (TextBox)lvPayments.FindControl("StopDateEditTextBox");
if (ddlFrequency.SelectedValue == "5")
{
textBoxStopDate.Enabled = false;
}
ASKER
Sorry, I have now solved this error by using the attached code.
There is now no error but whenever I choose the value in the dropdown that should disable my textbox the textbox remains enabled as if the autopostback is not occurring?
There is now no error but whenever I choose the value in the dropdown that should disable my textbox the textbox remains enabled as if the autopostback is not occurring?
DropDownList ddlFrequency = (DropDownList)lvPayments.InsertItem.FindControl("FrequencyInsertDDL");
TextBox textBoxStopDate = (TextBox)lvPayments.InsertItem.FindControl("StopDateInsertTextBox");
if (ddlFrequency.SelectedValue == "5")
{
textBoxStopDate.Enabled = false;
}
Make sure:
1. dropdown has the 'AutoPostBack' property set to 'true'
2. The 'textbox' which is being disables is inside the update panel.
3. Code reaches to the block:
if (ddlFrequency.SelectedValu e == "5")
{
textBoxStopDate.Enabled = false;
}
1. dropdown has the 'AutoPostBack' property set to 'true'
2. The 'textbox' which is being disables is inside the update panel.
3. Code reaches to the block:
if (ddlFrequency.SelectedValu
{
textBoxStopDate.Enabled = false;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Control tb = find text box control;
if (dropdown.SelectedValue='S
{
tb.Enabled=false;
}
Set autopostback property of dropdown to true.
The listview control should be inside the update panel.