Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

Last post 05-09-2008 1:24 PM by funluckykitty. 17 replies.

Sort Posts:

  • Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 1:49 PM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150

    I have two panels that display based upon a selected radio button.    In two of the four panels, there is a field name "attyID", which is a drop down box.    The AttyID is then inserted into SQL via a stored procedure if two of the four panels are selected.  But I don't understand why I can't name the fields the same name since only one panel is ever visible.  Since I can't name them the same, how do I handle inserting two fields with different names into my table via the sql stored procedure?

  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 2:18 PM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    A Panel control is not a templated control. Therefore, the controls IDs within must be unique.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 2:29 PM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150

    Ed, that makes sense, but doesn't make things easy for me.   How do I deal with this then?  If either of the two panels is displayed, I need to enter that attyID into sql into one field in the database.   So, if in panel 1, it's attyIDPanel1 and in panel 2 it's attyIDPanel2, how do I pass them into the same databasefield, because I don't want two separate columns in my database. 

    In the old asp days, I'd do an If Then around the fields and I'd be ok... just not sure how to handle this in vb.NET within the two different panels.    I thought that since one panel is displayed while the other is hidden, it would be ok to name them the same.  

  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 2:42 PM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    It's a pain, but you'll just have to know that if one Panel is displayed, then you'll retrieve the control within it, otherwise you'll retrieve the control from the other control.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 2:46 PM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150

    Argh... that's a little over my head.   Do I want to do an if/then in my stored procedure? 

  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 2:52 PM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    No, do this prior to calling your stored procedure. This should be in the business logic.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 3:00 PM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150

    Argh, I'm not sure of the syntax to do that.  I understand what you are suggesting, but don't know how to tell the page that if panel 1 is visible, then attyIDPanel  is included in panel one  else if   panel 2 exists then use the attyIDPanel in panel 2. 

    Do you have time to show me some code on how to do this? 

  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 3:25 PM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    Use a ternary statement to extract the proper control. This assumes the names of your controls are "attyIdPanel1" and "attyIDPanel2" respectively.

    DropDownList attyID = attyIDPanel1.Visible ? attyIDPanel1 : attyIDPanel2;

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-08-2008, 8:15 PM

     blanket approval ecbruck.

     

  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-09-2008, 10:13 AM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150

    Ed, I understand the statement, but where does it go?  In the page or in the code behind? 

    And since I'm using vb.net, do I use IIF 
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-09-2008, 10:18 AM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    Code-behind.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-09-2008, 11:12 AM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150

    Converting your sample to vb.net, I get the following, Dim attyID As DropDownList = IIf(attyIDPanel1.Visible,attyIDPanel1,attyIDPanel2)

     

  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-09-2008, 11:21 AM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    I'd have to debug it to see exactly what object is causing the problem.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-09-2008, 11:26 AM
    • Loading...
    • funluckykitty
    • Joined on 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 150
    Is my statement right and does it belong in the Page Load?  I thought maybe it should be this instead... 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim ClientToSearch As DropDownList = IIf(Panel1.Visible, Panel1, Panel2) End Sub
  • Re: Why can I name two dropdown boxes the same name since they are in different panels and boh panels can't be displayed at the same time?

    05-09-2008, 11:41 AM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator

    First off, you're trying to cast a Panel control to a DropDownList. If you're wanting to retrieve a Panel control, then make sure you set your evaluation to a control of type Panel. Secondly. I'm lost as far as what you're trying to do again with the retrieved control.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
Page 1 of 2 (18 items) 1 2 Next >