Results 1 to 20 of 20

Thread: Server control not accessible in code-behind?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Server control not accessible in code-behind?

    I have a web page that I am converting from classic ASP to ASP.Net. There are a bunch of "Select" controls (DropDown Boxes) that I am changing to DropDownList controls. I have set the "runat='server'" in all of these controls. However, when I go to the code-behind, they are not visible/accessible. I have tried to "clean" the solution and rebuild it and the controls still won't show. Any ideas?

    Thanks,
    Last edited by blakemckenna; Apr 16th, 2013 at 11:41 AM.
    Blake

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    Does anyone have any ideas on this? I'm really under the gun here and need to get this project finished. Sorry for the nagging!
    Blake

  3. #3
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    is autopostback = "true" in that line somewhere?
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    No, the autopostback = true isn't in the declaration of the control and I don't want it to be an autopostback either.
    Blake

  5. #5
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    without post back certain controls will not fire the event. do you have autoeventwireup set to true?
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    No I don't have autoeventwireup = true....
    Blake

  7. #7
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Myform" %>

    should be at the top of your ASPX file. Try that.

    also declare your event signature in the control layout, so for a text box OnTextChanged="EventYouDefined"
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    Unfortunately that did not make a difference!
    Blake

  9. #9
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    DDL has to be marked as autopostback = true to fire the selected index changed event.
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    Let me try that and see what that does!
    Blake

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    That did not affect it either.
    Blake

  12. #12
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Server control not accessible in code-behind?

    Not showing a runat server control may occur if you are running C# and VS2008. Is it possible that you have this combination?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    when you say running C#...are you referring to that being the development language that I am using for this particular project? If so, I'm using VB.Net. But I am using VS 2008.
    Blake

  14. #14
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    language should not matter to the HTML, i just happen to write this one in C# is all.

    can you post the offending markup for the control??
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    Here is the markup for the just one of the controls. There are a handful of others just like it.

    Code:
                                        <asp:DropDownList ID="drpClient" runat="server" style="width: 260px">
                                            <asp:ListItem Value="0">--- Select Client ---</asp:ListItem>
                                        </asp:DropDownList>
    Blake

  16. #16
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    Code:
    <asp:DropDownList ID="ddlCheckType" runat="server" Width="132px" OnSelectedIndexChanged="ddlCheckType_SelectedIndexChanged" AutoPostBack="True">
               
    </asp:DropDownList>
    this declaration workes in 12, should work in 08 too, i just declare my list items values in code instead of markup, but that part dont matter.
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    I showed this code to another one of our developers and he added it to his code and tried accessing it in the code-behind and didn't have any trouble. He did some inquiring and the census was that it appears to be a setting within VS 2008. I submitted a ticket to Experts-Exchange as well.
    Blake

  18. #18
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: Server control not accessible in code-behind?

    that could be...generally you print out the code due for upgrading and rewrite it. upgrading from classic to .net would involve more headaches than just redoing the whole thing.
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  19. #19
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Server control not accessible in code-behind?

    Do you have the latest service pack installed?
    Also if you add a dropdownlist, go to the designers mode and double click at it, what happens?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Server control not accessible in code-behind?

    I actually just went into the designer.vb of the page and manually inserted the controls. It didn't take to long. I will try what you suggested Sapator just to see what happens.

    Thanks
    Blake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width