Text Changed Event Not Firing - c#

I got 2 Dropdown list, 1 Radio button and 1 Textbox along with a Button. I am trying to Disable Button when Dropdowns,Radio Buttons are not selected alon with Empty Textbox. I am able to Disable the button for Dropdown and Radio Button and displaying the message as "Invalid Selection" and for this I have written code on Selected Index Change Event and even in Button Click Event and its working fine. But I am not able to Disable the Button when the Textbox is Empty. Want this Button to be Enabled only when I type something in Textbox and when i try to Click the Button When Textbox is Empty i need a message to be displayed saying "Please Enter a Comment". I have tried Text Changed Event for TextBox too but it is not firing. And Please anybody let me know how to put all these together in Button Click event using Flags.
Note: There are 2 Error messages to be displayed upon Button Click. This should come in loop with Flags being assigned.
So far I have tried this,
Button Click Code:
protected void BtnSave_Click(object sender, EventArgs e)
{
if (DrpForYear.SelectedItem.Text == "Please Select" || DrpForMonth.SelectedItem.Text == "Please Select" || RadView.SelectedItem.Text == "")
{
LblErr.Text = "Invalid Selection!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.Gray;
BtnSave.ForeColor = Color.Red;
}
else
{
DTO objc = new DTO();
int Flag = 0;
LblLogdInUsername.Text = Session["Username"].ToString();
objc.LogdInUsername = LblLogdInUsername.Text;
objc.DateTime = DateTime.Now;
objc.Comments = Server.HtmlEncode(this.TxtComments.Text);
objc.Company = LblCompany.Text;
LblName.Text = Session["Name"].ToString();
objc.Name = LblName.Text;
objc.Year = DrpForYear.SelectedItem.Text;
objc.Month = DrpForMonth.SelectedItem.Text;
objc.ViewPreference = RadView.SelectedItem.Text;
int X = obj.InsertButtonComment(objc);
if (X >= 0)
{
Flag = 1;
}
else
{
Flag = 0;
}
if (Flag == 1)
{
LblSuccess.Visible = true;
LblSuccess.Text = "Comment Saved";
LblErr.Visible = false;
BtnSave.Enabled = true;
}
else
{
LblErr.Visible = true;
LblErr.Text = "Failed To Save Comment!!!";
LblSuccess.Visible = false;
}
objc.LogdInUsername = Convert.ToString(Session["LogdInUsername"]);
DataSet GrdVC = obj.GetButtonComment(objc);
DataView GrdViewC = new DataView();
GrdViewC.Table = GrdVC.Tables[0];
gvData.DataSource = GrdViewC;
gvData.DataBind();
TxtComments.Text = "";
DrpForYear.ClearSelection();
DrpForMonth.ClearSelection();
RadView.Text = "";
}
}
DDL Selected Index Codes:
protected void DrpForYear_SelectedIndexChanged(object sender, EventArgs e)
{
if (DrpForYear.SelectedItem.Text == "Please Select")
{
LblErr.Text = "Invalid Selection!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.Gray;
BtnSave.ForeColor = Color.Red;
}
else
{
BtnSave.Enabled = true;
BtnSave.BackColor = ColorTranslator.FromHtml("#666666");
BtnSave.ForeColor = Color.White;
}
}
protected void DrpForMonth_SelectedIndexChanged(object sender, EventArgs e)
{
if (DrpForMonth.SelectedItem.Text == "Please Select")
{
LblErr.Text = "Invalid Selection!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.LightGray;
BtnSave.ForeColor = Color.Red;
}
else
{
BtnSave.Enabled = true;
BtnSave.BackColor = ColorTranslator.FromHtml("#666666");
BtnSave.ForeColor = Color.White;
}
}
Textbox Changed Event Code:
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if (TxtComments.Text == "")
{
LblErr.Text = "Please Enter a Comment!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.LightGray;
BtnSave.ForeColor = Color.Red;
}
else if (TxtComments.Text != "")
{
BtnSave.Enabled = true;
BtnSave.BackColor = ColorTranslator.FromHtml("#666666");
BtnSave.ForeColor = Color.White;
}
}
aspx code:
<asp:TextBox ID="TxtComments" runat="server" BorderColor="#666666" BorderWidth="1px"
Font-Names="Calibri" Font-Size="Small" ForeColor="#034599" Height="106px" TextMode="MultiLine" Width="617px" ontextchanged="TxtComments_TextChanged">

1. You need to set AutoPostBack property of the TextBox to True .
2. while comparing the input String with EmptyString, you need to Trim the input so that whitespaces would be removed.
or
you can use String.IsNullOrWhiteSpace() to check for null,empty and whitespaces.
Try This:
Design Code
<asp:TextBox ID="TxtComments" runat="server" OnTextChanged="TxtComments_TextChanged"
AutoPostBack="True"></asp:TextBox>
Code Behind: using Trim() function
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if (TxtComments.Text.Trim().Equals(""))
{
LblErr.Text = "Please Enter a Comment!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.LightGray;
BtnSave.ForeColor = Color.Red;
}
else
{
BtnSave.Enabled = true;
BtnSave.BackColor = ColorTranslator.FromHtml("#666666");
BtnSave.ForeColor = Color.White;
}
}
or using String.IsNullOrWhiteSpace() function
protected void TxtComments_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(TxtComments.Text))
{
LblErr.Text = "Please Enter a Comment!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.LightGray;
BtnSave.ForeColor = Color.Red;
}
else
{
BtnSave.Enabled = true;
BtnSave.BackColor = ColorTranslator.FromHtml("#666666");
BtnSave.ForeColor = Color.White;
}
}
Solution 2: display TextBox error message as first error
protected void BtnSave_Click(object sender, EventArgs e)
{
if (TxtComments.Text.Trim().Equals(""))
{
LblErr.Text = "Please Enter a Comment!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.LightGray;
BtnSave.ForeColor = Color.Red;
}
else if (DrpForYear.SelectedItem.Text == "Please Select" || DrpForMonth.SelectedItem.Text == "Please Select" || RadView.SelectedItem.Text == "")
{
LblErr.Text = "Invalid Selection!!!";
LblErr.Visible = true;
BtnSave.Enabled = false;
BtnSave.BackColor = Color.Gray;
BtnSave.ForeColor = Color.Red;
}
else
{
/*your code*/
}
}

You need to set
TxtComments.AutoPostBack= true
in Code behind
Or
AutoPostBack="True" in TextBox Design Page
Like this
<asp:TextBox ID="TxtComments" runat="server" AutoPostBack="True"></asp:TextBox>

set Autopostback into true
<asp:TextBox ID="TxtComments" runat="server" BorderColor="#666666" BorderWidth="1px" Font-Names="Calibri" Font-Size="Small" ForeColor="#034599" Height="106px" TextMode="MultiLine" Width="617px" ontextchanged="TxtComments_TextChanged" AutoPostBack="true">

Related

Enable and Disable buttons, labels based on some conditions

I have 5 buttons and 5 labels next to each button. When i run the app i expect the first button to be enabled and the the rest disabled and greyed out with the labels. after i click the first button it should disable with the label and enable the second button, and so forth with all the other buttons.
this way is to long, is there a better way of doing this?
private void Form1_Load(object sender, EventArgs e)
{
btn1.Enabled = true;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = true;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
private void btn1_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = true;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = false;
lblStep2.Enabled = true;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
private void btn2_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = true;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = false;
lblStep2.Enabled = false;
lblStep3.Enabled = true;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
}
private void btn3_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = true;
btn5.Enabled = false;
lblStep1.Enabled = false;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = true;
lblStep5.Enabled = false;
}
private void btn4_Click(object sender, EventArgs e)
{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = true;
lblStep1.Enabled = false;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = true;
}
private void btn5_Click(object sender, EventArgs e)
{
btn1.Enabled = true;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
lblStep1.Enabled = true;
lblStep2.Enabled = false;
lblStep3.Enabled = false;
lblStep4.Enabled = false;
lblStep5.Enabled = false;
}
Let all these buttons and labels are inside a container(if it doesn't mean that you can use this.Controls as well if the form contains these buttons and labels only). Let it be pnlContainer, Now you can try something like this:
public void ButtonController(Button buttonToEnable, Label labelToenable)
{
foreach (Control ctrl in panel1.Controls)
{
if (ctrl == buttonToEnable || ctrl == labelToenable)
{
ctrl.Enabled = true;
}
else
{
ctrl.Enabled = false;
}
}
}
So in Form1_Load you want to enable btn1 and lblStep1 so the call should be :
ButtonController(btn1,lblStep1);
For btn1_Click the method call will be like ButtonController(btn2,lblStep2);. in short, you can pass the button and label that you want to enable to this method, which will disable rest of controls in the container.

ASP.NET visible=true doesn´t show buttons

I have a problem by setting my Buttons visible.
I created some buttons in a MasterPage and set their visibility false.
(button.Visible = false;)
After pressing a button I am redirected to another page.
On this Page (a child from MasterPage) I want to set some buttons visible (Master.FindControl("button").Visible=true), but this is my problem. It doesn´t show up.
MasterPage.master:
<asp:Button ID="b_home" runat="server" Text="Home" CssClass="button" OnClick="b_home_Click"/>
<asp:Button ID="b_profil" runat="server" Text="Profil" CssClass="button" OnClick="b_profil_Click"/>
<asp:Button ID="b_reservieren" runat="server" Text="Reservieren" CssClass="button" OnClick="b_reservieren_Click"/>
<asp:Button ID="b_verleihhistorie" runat="server" Text="Verleihhistorie" CssClass="button" OnClick="b_verleihhistorie_Click"/>
<asp:Button ID="b_warenausgang" runat="server" Text="Warenausgang" CssClass="button" OnClick="b_warenausgang_Click"/>
<asp:Button ID="b_wareneingang" runat="server" Text="Wareneingang" CssClass="button" OnClick="b_wareneingang_Click"/>
<asp:Button ID="b_neueKunden" runat="server" Text="Neue Kunden" CssClass="button" OnClick="b_neueKunden_Click"/>
<asp:Button ID="b_kontakte" runat="server" Text="Kontakte" CssClass="button" OnClick="b_kontakte_Click"/>
</div>
Master.master.cs
protected void Page_Load(object sender, EventArgs e)
{
b_home.Visible = true;
b_kontakte.Visible = true;
b_profil.Visible = false;
b_reservieren.Visible = false;
b_verleihhistorie.Visible = false;
b_warenausgang.Visible = false;
b_wareneingang.Visible = false;
b_neueKunden.Visible = false;
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if(MasterPage.istAngemeldet)
{
// .p = db.Persons.Where(s => s.Email==benutzername && s.Passwort== passwort).FirstOrDefault();
l_willkommen.Text= "Herzlich Willkommen bei Bee-Coop.at, " + MasterPage.p.Vorname + "!";
LinkButton l1 = (LinkButton)Master.FindControl("LinkButton1");
l1.Text = "[Abmelden]";
#region SideMenu_Control
switch(MasterPage.hatRolle)
{
case 0: Master.FindControl("b_home").Visible = true;
Master.FindControl("b_kontakte").Visible = true;
Master.FindControl("b_profil").Visible = true;
Master.FindControl("b_reservieren").Visible = true;
Master.FindControl("b_verleihhistorie").Visible = true;
Master.FindControl("b_warenausgang").Visible = true;
Master.FindControl("b_wareneingang").Visible = true;
Master.FindControl("b_neueKunden").Visible = true;
break;
case 1: Master.FindControl("b_home").Visible = true;
Master.FindControl("b_kontakte").Visible = true;
Master.FindControl("b_profil").Visible = true;
Master.FindControl("b_reservieren").Visible = true;
Master.FindControl("b_verleihhistorie").Visible = true;
Master.FindControl("b_warenausgang").Visible = true;
Master.FindControl("b_wareneingang").Visible = true;
break;
case 2: Master.FindControl("b_home").Visible = true;
Master.FindControl("b_kontakte").Visible = true;
Master.FindControl("b_profil").Visible = true;
Master.FindControl("b_reservieren").Visible = true;
Master.FindControl("b_verleihhistorie").Visible = true;
break;
case 3: Master.FindControl("b_home").Visible = true;
Master.FindControl("b_kontakte").Visible = true;
break;
}
#endregion
}
}
you start the page_load event everytime the page gets shown, so you set the control's visibility to false you need to change ur code to:
protected void Page_Load(object sender, EventArgs e)
{
switch(MasterPage.hatRolle)
{
case 0: b_home.Visible = true;
b_kontakte.Visible = true;
b_profil.Visible = true;
b_reservieren.Visible = true;
b_verleihhistorie.Visible = true;
b_warenausgang.Visible = true;
b_wareneingang.Visible = true;
b_neueKunden.Visible = true;
break;
//case 1: .....
//...........
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
b_home.Visible = true;
b_kontakte.Visible = true;
b_profil.Visible = false;
b_reservieren.Visible = false;
b_verleihhistorie.Visible = false;
b_warenausgang.Visible = false;
b_wareneingang.Visible = false;
b_neueKunden.Visible = false;
}
}

How do i get an information label to appear as i type and disappear when i delete the text

I have a couple of text boxes that i have initially hidden and what I want to do is as the users type I would like the next text box along with the label that goes with it to appear to notify of the next question.
At the same time if they change their mind and delete their response to the first question the next text box and label will disappear once the text has been deleted.
Here is my current code:
private void CreditScoreBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsControl(e.KeyChar) || char.IsDigit(e.KeyChar))
e.Handled = false;
else
e.Handled = true;
if(CreditScoreBox.Text == "")
{
MakeBox.Visible = false;
MakeLabel.Visible = false;
ModelBox.Visible = false;
ModelLabel.Visible = false;
CreditLevelLabel.Visible = false;
}
else
{
MakeBox.Visible = true;
MakeBox.Enabled = true;
MakeLabel.Visible = true;
CreditLevelLabel.Visible = true;
}
I have tried using the TextChanged event with the same result.
I created a Form, with 2 textbox and 1 label. If text exist in textbox1 then label1 and textbox2 become available:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
textBox2.Enabled = false;
textBox2.Visible = false;
label1.Visible = false;
}
else
{
textBox2.Enabled = true;
textBox2.Visible = true;
label1.Visible = true;
}
}

Stop enabling Radiobutton after button click?

I have radio buttons in my project which should get disabled if one of the 2 options from a list of 4 attributes is selected. This is my code:
<asp:DropDownList ID="drpLType" runat="server" CssClass="drp">
<asp:ListItem Value="0" Selected="True">Professional</asp:ListItem>
<asp:ListItem Value="1">Enterprise</asp:ListItem>
<asp:ListItem Value="2">Maintanence</asp:ListItem>
<asp:ListItem Value="3">Reporting</asp:ListItem>
</asp:DropDownList>
I used javascript for this purpose:
function funMeapSupportValidate(val)
{
switch(val)
{
case "0" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false;
break;
case "1" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false;
break;
case "2" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true;
break;
case "3" :
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;
document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true;
break;
default:
break;
}
}
At my backend code:
protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpLType.SelectedValue == "Professional")
{
rdoMeapSupport.Enabled = true;
}
if (drpLType.SelectedValue == "Enterprise")
{
rdoMeapSupport.SelectedValue = null;
rdoMeapSupport.Enabled = true;
}
if ((drpLType.SelectedValue == "Maintanence") || (drpLType.SelectedValue == "Reporting"))
{
rdoMeapSupport.Enabled = false;
rdoMeapSupport.ClearSelection();
}
}
Now the problem is there are two buttons on my website. Whenever I click those buttons, the radio buttons get activated even when I have selected Maintenance or Reporting . How do I disable that?
On my page load:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Tab1.CssClass = "Clicked";
MainView.ActiveViewIndex = 0;
if (drpLType.SelectedValue == "Professional")
{
rdoMeapSupport.Enabled = true;
rdoMeapSupport.SelectedValue = "Yes";
}
drpLType_SelectedIndexChanged();
}
drpLType.Attributes.Add("onchange", "javascript:funMeapSupportValidate(this.value);");
}
Well I used this
<INPUT type="radio" name="myButton" value="theValue"
onclick="this.checked=false;
alert('Sorry, this option is not available!')">
I finally resolved the error in the following manner.
protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpLType.SelectedValue == "1")
{
rdoMeapSupport.Enabled = true;
}
if (drpLType.SelectedValue == "2")
{
rdoMeapSupport.SelectedValue = null;
rdoMeapSupport.Enabled = true;
}
if ((drpLType.SelectedValue == "3") || (drpLType.SelectedValue == "4"))
{
rdoMeapSupport.Enabled = false;
rdoMeapSupport.ClearSelection();
}
}

RadioButtonList: OnSelectedIndexChanged not firing

I have an aspx page where i dynamically add a radiobuttonlist with OnSelectedIndexChanged event. In the event i check for the selected items. i have 2 items.
For the first item,the event is firing well, However if i choose the other option the event is not firing: below the code..
The event is only firing is i change from "Some provided" to "All provided" the other way it is not working
Adding the RBL:
RadioButtonList dControl_b = new RadioButtonList();
dControl_b.ID = "rbl_MinCriteria";
dControl_b.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
dControl_b.CssClass = "Font";
dControl_b.Font.Name = "Arial";
dControl_b.Font.Size = 8;
dControl_b.ToolTip = "";
dControl_b.SelectedIndex = -1;
dControl_b.SelectedIndexChanged += new EventHandler(rbl_MinCriteria_SelectedIndexChanged);
dControl_b.AutoPostBack = true;
Checking the selected item:
if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
{
cbl_MinimumCriteria.Items[0].Selected = true;
cbl_MinimumCriteria.Items[1].Selected = true;
cbl_MinimumCriteria.Items[2].Selected = true;
cbl_MinimumCriteria.Items[3].Selected = true;
cbl_MinimumCriteria.Enabled = false;
//*************************************************************
if (ddl_CountryOccurence.SelectedValue != "Please choose")
{
ddl_CountryOccurence.Enabled = false;
}
else
{
ddl_CountryOccurence.Enabled = true;
}
//*************************************************************
if (tb_DueDate.Text != "")
{
tb_DueDate.Enabled = false;
}
else
{
tb_DueDate.Enabled = true;
}
OtherControlI.Enabled = false;
OtherControlII.Enabled = false;
OtherControlIII.Enabled = false;
}
if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
{
cbl_MinimumCriteria.Items[0].Selected = false;
cbl_MinimumCriteria.Items[1].Selected = false;
cbl_MinimumCriteria.Items[2].Selected = false;
cbl_MinimumCriteria.Items[3].Selected = false;
cbl_MinimumCriteria.Enabled = true;
//*************************************************************
if (ddl_CountryOccurence.SelectedValue != "Please choose")
{
ddl_CountryOccurence.Enabled = false;
}
else
{
ddl_CountryOccurence.Enabled = true;
}
//*************************************************************
if (tb_DueDate.Text != "")
{
tb_DueDate.Enabled = false;
}
else
{
tb_DueDate.Enabled = true;
}
OtherControlI.Enabled = false;
OtherControlI.SelectedIndex = -1;
OtherControlII.Enabled = false;
OtherControlII.SelectedIndex = -1;
OtherControlIII.Enabled = false;
OtherControlIII.SelectedIndex = -1;
}
Any help and Comment is much appreciated
This is for people who find this question from Google:
On the RadioButtonList, set the AutoPostBack property to true.
RadioButtonList OnSelectedIndexChanged
I have this problem and solved it.
For raising onselectedindexchanged event of RadioButtonList , check below items:
<asp:RadioButtonList ID="rdlCondition" runat="server" AutoPostBack="True"
onselectedindexchanged="rdlCondition_SelectedIndexChanged">
and in the Page_Load set them with code :
rdlCondition.AutoPostBack = true;
rdlCondition.SelectedIndexChanged += new EventHandler (rdlCondition_SelectedIndexChanged);
Looking at the code above there seems to be alot of code reuse. I reorganized your code a bit (assuming you didnt leave anything out). Keep in mind I never tested it.
protected void rbl_MinCriteria_SelectedIndexChanged(object sender,EventArgs e)
{
if (rbl_MinCriteria.SelectedIndex<0) return; //If nothing is selected then do nothing
OtherControlI.Enabled = false;
OtherControlII.Enabled = false;
OtherControlIII.Enabled = false;
if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
{
cbl_MinimumCriteria.Items[0].Selected = true;
cbl_MinimumCriteria.Items[1].Selected = true;
cbl_MinimumCriteria.Items[2].Selected = true;
cbl_MinimumCriteria.Items[3].Selected = true;
cbl_MinimumCriteria.Enabled = false;
}
if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
{
cbl_MinimumCriteria.Items[0].Selected = false;
cbl_MinimumCriteria.Items[1].Selected = false;
cbl_MinimumCriteria.Items[2].Selected = false;
cbl_MinimumCriteria.Items[3].Selected = false;
cbl_MinimumCriteria.Enabled = true;
OtherControlI.SelectedIndex = -1;
OtherControlII.SelectedIndex = -1;
OtherControlIII.SelectedIndex = -1;
}
//*************************************************************
if (ddl_CountryOccurence.SelectedValue != "Please choose")
{
ddl_CountryOccurence.Enabled = false;
}
else
{
ddl_CountryOccurence.Enabled = true;
}
//*************************************************************
if (tb_DueDate.Text != "")
{
tb_DueDate.Enabled = false;
}
else
{
tb_DueDate.Enabled = true;
}
}
I know this doesn't help your current problem but this is just a suggestion. If you could post the code where your actually adding the values to the list I could help a bit more.
EDIT: Your problem could be your not setting the value of your items, only the text. Try using rbl_MinCriteria.SelectedItem.Text =="All provided" instead.
I've made a sample aspx page, and added one panel in .aspx like below:
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
And in code behind, I've added following code:
protected void Page_Load(object sender, EventArgs e)
{
RadioButtonList dControl_b = new RadioButtonList();
dControl_b.ID = "rbl_MinCriteria";
dControl_b.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
dControl_b.CssClass = "Font";
dControl_b.Font.Name = "Arial";
dControl_b.Font.Size = 8;
dControl_b.ToolTip = "";
dControl_b.SelectedIndex = -1;
dControl_b.SelectedIndexChanged += new EventHandler(rbl_MinCriteria_SelectedIndexChanged);
dControl_b.AutoPostBack = true;
dControl_b.Items.Add(new ListItem("All provided"));
dControl_b.Items.Add(new ListItem("Some provided"));
Panel1.Controls.Add(dControl_b);
}
protected void rbl_MinCriteria_SelectedIndexChanged(object sender,EventArgs e)
{
RadioButtonList rbl_MinCriteria = (RadioButtonList)Panel1.FindControl("rbl_MinCriteria");
if(rbl_MinCriteria.SelectedItem.ToString() == "All provided")
{
}
if (rbl_MinCriteria.SelectedItem.ToString() == "Some provided")
{
}
}
The event is FIRING EVERY TIME the radio button listitem is changed.
So, I'm afraid, you have done something wrong elsewhere. Good luck.

Categories

Resources