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();
}
}
Related
I have an ASP button click method that I want to change from a user clicking the button
<asp:Button id="createInvoice" runat="server" OnClick="InvoiceBtn_Click" Text="Create Invoice button" />
to executing on Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
AsyncMode = true;
if (!dictionary.ContainsKey("accessToken"))
{
if (Request.QueryString.Count > 0)
{
var response = new AuthorizeResponse(Request.QueryString.ToString());
if (response.State != null)
{
if (oauthClient.CSRFToken == response.State)
{
if (response.RealmId != null)
{
realmId = response.RealmId;
if (!dictionary.ContainsKey("realmId"))
{
dictionary.Add("realmId", realmId);
}
}
if (response.Code != null)
{
authCode = response.Code;
Session["authcodes"] = authCode;
output("Authorization code obtained.");
PageAsyncTask t = new PageAsyncTask(performCodeExchange);
Page.RegisterAsyncTask(t);
Page.ExecuteRegisteredAsyncTasks();
}
}
else
{
output("Invalid State");
dictionary.Clear();
}
}
}
}
else
{
oauth.Visible = true;
connected.Visible = true;
}
}
#region button click events
public async void InvoiceBtn_Click()
{
if (dictionary.ContainsKey("realmId") && dictionary.ContainsKey("accessToken"))
{
Action<ServiceContext> apiCallFucntion = new Action<ServiceContext>(CreateInvoiceCall);
await QBOApiCall(apiCallFucntion);
}
else
{
lblQBOCall.Visible = true;
lblQBOCall.Text = "Access token not found.";
}
}
I changed the final else statement and final line in the method and it works. I'm sure it needs refactoring but it works.
else
{
oauth.Visible = true;
connected.Visible = true;
InvoiceBtn_Click(createInvoice, EventArgs.Empty);
}
InvoiceBtn_Click(createInvoice, EventArgs.Empty);
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;
}
}
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">
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.
I have a Dropdownlist (DDL1) when I select any item from this dropdownlist(DDL1), results in creation of another dropdownlist(DDL2), This contains some of the items.When I select other Item from DDL1 , Items will change in DDL2, this happens for the each different item selected in DDL1.
when I select a item from DDL2, label content must be shown, intially I'm making Label invisibe and in the code I changed the visibility to true and added content to it. But the label content is not shown when I select a item from DDL2.
Here is my Code
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Abe Books")
{
DropDownSeller.Visible = true;
lnkUsdBooks.Visible = true;
lnkUsdBooks.Text = "usedbooks#abe.com";
lnkUsdBooks.NavigateUrl = "mailto:usedbook#abe.com";
DropDownSeller.Visible = true;
DropDownSeller.Items.Remove("Chacha Choudary");
DropDownSeller.Items.Remove("SpiderMan");
DropDownSeller.Items.Remove("Amar chitra Katha");
DropDownSeller.Items.Remove("Chandamama");
DropDownSeller.Items.Remove("Mahabharata");
DropDownSeller.Items.Add("Amar chitra Katha");
DropDownSeller.Items.Add("Chandamama");
DropDownSeller.Items.Add("Mahabharata");
DropDownSeller.DataBind();
if (DropDownSeller.SelectedValue == "Amar chitra Katha")
{
lblPrice.Visible = true;
lblPrice.Text = "$69.99";
}
else if (DropDownSeller.SelectedValue == "Chandamama")
{
lblPrice.Visible = true;
lblPrice.Text = "$59.99";
}
else if (DropDownSeller.SelectedValue == "Mahabharata")
{
lblPrice.Visible = true;
lblPrice.Text = "$49.99";
}
else
{
lblPrice.Visible = false;
}
}
Any ideas on this are appreciated
Thanks,
Remove if (!Page.IsPostBack) from the DropDownList1_SelectedIndexChanged because when the page postbacks this condition will be false. Because your page is posting back to the server that's why it is not visible and not showing.
In short your DropDownList1_SelectedIndexChanged should be like..
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "Abe Books")
{
DropDownSeller.Visible = true;
lnkUsdBooks.Visible = true;
lnkUsdBooks.Text = "usedbooks#abe.com";
lnkUsdBooks.NavigateUrl = "mailto:usedbook#abe.com";
DropDownSeller.Visible = true;
DropDownSeller.Items.Clear(); // it will clear all the items, instead you are removing one by one
DropDownSeller.Items.Add("Amar chitra Katha");
DropDownSeller.Items.Add("Chandamama");
DropDownSeller.Items.Add("Mahabharata");
DropDownSeller.DataBind();
}
protected void DropDownSeller_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownSeller.SelectedValue == "Amar chitra Katha")
{
lblPrice.Visible = true;
lblPrice.Text = "$69.99";
}
else if (DropDownSeller.SelectedValue == "Chandamama")
{
lblPrice.Visible = true;
lblPrice.Text = "$59.99";
}
else if (DropDownSeller.SelectedValue == "Mahabharata")
{
lblPrice.Visible = true;
lblPrice.Text = "$49.99";
}
else
{
lblPrice.Visible = false;
}
}