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,
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!
Re: Server control not accessible in code-behind?
is autopostback = "true" in that line somewhere?
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.
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?
Re: Server control not accessible in code-behind?
No I don't have autoeventwireup = true....
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"
Re: Server control not accessible in code-behind?
Unfortunately that did not make a difference!
Re: Server control not accessible in code-behind?
DDL has to be marked as autopostback = true to fire the selected index changed event.
Re: Server control not accessible in code-behind?
Let me try that and see what that does!
Re: Server control not accessible in code-behind?
That did not affect it either.
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?
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.
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??
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>
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.
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.
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.
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?
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