Click here to Skip to main content
15,916,835 members
Home / Discussions / ASP.NET
   

ASP.NET

 
SuggestionRe: SelectedIndexChanged for DropDown not fired when first item selected Pin
Richard Deeming19-Nov-23 21:56
mveRichard Deeming19-Nov-23 21:56 
QuestionDumb it down for one who's basically a beginner Pin
DalTXColtsFan15-Nov-23 5:31
DalTXColtsFan15-Nov-23 5:31 
OK, I'll put this in as few words as possible, and please bear with me if I am not clear, I'm still relatively new to this stuff:

So my company has a website we roll out to our customers, and the developers provided a base class to the consultants to use to create custom web parts. The website has a "design mode" built into it where an admin can divide the page up into sections, and basically assign a custom web part to that section of the page. The ascx and dll for the web part obviously have to be on the IIS server where the website can "see" it. I'm not sure exactly how that works technologically, i.e. if it's a master page with individual pages or if it's like a div or whatever.

Anyway, I tried to create a simple webpart with two dropdowns, one of which depends on the other, and a button. The labels and dropdowns appear to be initializing correctly. When I click the button, it correctly updates the label but it clears the dropdowns. Changing the selection in either dropdown appears to re-initialize the entire form including clearing the dropdowns.

Lastly, I could be wrong but I don't believe that the code in ddlCategory_SelectedIndexChanged is getting fired as a result of the dropdown getting clicked - I think it's only getting ran when I call it explicitly. Again, I could be wrong, but I feel like any time a "postback" is issued, only Page_Load is getting fired off, and the controls are all getting cleared/initialized before any of the code in Page_Load is actually run.

I'll pause there for a moment - does anyone see anything in *my* code that could be causing this incorrect result? Before I talk about how I could troubleshoot it within the framework of the rest of my company's website let's establish that.

Thanks
DTXCF

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="First2023WebUserControl.ascx.cs" Inherits="First2023Control.UserControls.First2023WebUserControl" %>
<asp:Label ID="Label1" runat="server" Text="Hello Year 2023"></asp:Label>
<p>
     </p>
Category:<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged">
</asp:DropDownList>
<p>
    Subcategory:
    <asp:DropDownList ID="ddlSubcategory" runat="server" AutoPostBack="True">
    </asp:DropDownList>
</p>
<p>
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</p>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>



using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Custom1.Custom2.Web.Framework;

namespace First2023Control.UserControls
{
//public partial class First2023WebUserControl : System.Web.UI.UserControl
public partial class First2023WebUserControl : Custom1.Custom2.Web.Framework.UserControlBase
{
[Property(DisplayName = "Message Text")]
public string MessageText
{
get
{
return Label1.Text;
}
set
{
Label1.Text = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{

if (IsPostBack == false)
{
ddlCategory.Items.Add("FirstCat");
ddlCategory.Items.Add("SecondCat");
ddlCategory_SelectedIndexChanged(sender, e);
}
else
{
Label1.Text = "I posted back";
}
}

protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = "The selected index changed";
if (ddlCategory.SelectedValue == "FirstCat")
{
ddlSubcategory.Items.Clear();
ddlSubcategory.Items.Add("FirstCatFirstSubCat");
ddlSubcategory.Items.Add("FirstCatSecondSubCat");
}
else
{
ddlSubcategory.Items.Clear();
ddlSubcategory.Items.Add("SecondCatFirstSubCat");
ddlSubcategory.Items.Add("SecondCatSecondSubCat");
}

}

protected void Button1_Click(object sender, EventArgs e)
{
Label3.Text = "Someone clicked the button";
}
}
}
AnswerRe: Dumb it down for one who's basically a beginner Pin
Andre Oosthuizen15-Nov-23 7:25
mveAndre Oosthuizen15-Nov-23 7:25 
GeneralRe: Dumb it down for one who's basically a beginner Pin
DalTXColtsFan15-Nov-23 11:48
DalTXColtsFan15-Nov-23 11:48 
GeneralRe: Dumb it down for one who's basically a beginner Pin
Andre Oosthuizen16-Nov-23 5:36
mveAndre Oosthuizen16-Nov-23 5:36 
Questioncan't build blazor library in azure pipeline Pin
Super Lloyd6-Sep-23 17:08
Super Lloyd6-Sep-23 17:08 
AnswerRe: can't build blazor library in azure pipeline Pin
Super Lloyd6-Sep-23 18:27
Super Lloyd6-Sep-23 18:27 
QuestionBlazor component debugging Pin
Super Lloyd23-Aug-23 14:16
Super Lloyd23-Aug-23 14:16 
AnswerRe: Blazor component debugging Pin
Super Lloyd24-Aug-23 17:27
Super Lloyd24-Aug-23 17:27 
QuestionHTML SELECT CONTROL WITH RUNAT="SERVER Pin
tchia_k30-Jul-23 3:53
professionaltchia_k30-Jul-23 3:53 
AnswerRe: HTML SELECT CONTROL WITH RUNAT="SERVER Pin
Richard Deeming30-Jul-23 22:14
mveRichard Deeming30-Jul-23 22:14 
Question"Context.UserIdentifier" of SignalR is always null when I use CustomAuthenticationStateProvider in Blazor Server App Pin
Alex Wright 202221-Jul-23 3:45
Alex Wright 202221-Jul-23 3:45 
SuggestionRe: "Context.UserIdentifier" of SignalR is always null when I use CustomAuthenticationStateProvider in Blazor Server App Pin
Richard Deeming23-Jul-23 23:17
mveRichard Deeming23-Jul-23 23:17 
QuestionIs is possible to import an excel file with hyperlinks? Pin
samflex16-Jul-23 17:25
samflex16-Jul-23 17:25 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
Richard MacCutchan16-Jul-23 21:45
mveRichard MacCutchan16-Jul-23 21:45 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
samflex17-Jul-23 5:26
samflex17-Jul-23 5:26 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
Richard MacCutchan17-Jul-23 5:29
mveRichard MacCutchan17-Jul-23 5:29 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
samflex18-Jul-23 3:43
samflex18-Jul-23 3:43 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
Richard MacCutchan18-Jul-23 4:40
mveRichard MacCutchan18-Jul-23 4:40 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
RedDk18-Jul-23 7:19
RedDk18-Jul-23 7:19 
AnswerRe: Is is possible to import an excel file with hyperlinks? Pin
Andre Oosthuizen16-Jul-23 23:59
mveAndre Oosthuizen16-Jul-23 23:59 
AnswerRe: Is is possible to import an excel file with hyperlinks? Pin
Richard Andrew x6424-Jul-23 3:19
professionalRichard Andrew x6424-Jul-23 3:19 
GeneralRe: Is is possible to import an excel file with hyperlinks? Pin
samflex24-Jul-23 6:34
samflex24-Jul-23 6:34 
QuestionIllustrating ad emails Pin
Ali Al Omairi(Abu AlHassan)10-Jul-23 2:35
professionalAli Al Omairi(Abu AlHassan)10-Jul-23 2:35 
QuestionAdvise on how to reuse code behind in asp.net VB pages Pin
Member 875830229-Jun-23 16:25
Member 875830229-Jun-23 16:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.