|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can't access webpage's controls from the code-behind file after putting it in a <asp:LoginView/>After I moved my Checkbox control 'inside' a <asp:LoginView />, my code-behind file isn't compiling saying that: "The name 'MyCheckbox' does not not exist in the current context." Basically, when the 'administrator', and only the administrator, logs into the site (from another page), I want him to check a checkbox on this page. It all worked fine with anonymous access before (without the username and roles set up). I'm not too sure why one shouldn't access the ASP controls from code. How can my code-behind file access ASP.NET 2.0 controls on my webpage when the controls are embedded inside a <asp:LoginView> ? It looks like this: <asp:LoginView ID="LoginView1" runat="server"> <AnonymousTemplate> Anonymous template here... </AnonymousTemplate> <RoleGroups> <asp:RoleGroup Roles="Administrator"> <ContentTemplate> <asp:LoginStatus ID="LoginStatus" runat="server" LogoutImageUrl="Graphics/logout.jpg" Visible="false" /> <asp:Button ID="ButtonInsertNew" runat="server" Text="Insert New" OnClick="ButtonInsertNew_Click" /> <asp:Label ID="LabelError" runat="server" ForeColor="Red" Width="625px"></asp:Label> <asp:Panel ID="PanelFileUpload" runat="server" > <asp:CheckBox ID="CheckBoxPDF" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBoxPDF_CheckedChanged" Text="PDF Filename" Width="125" /> <asp:FileUpload ID="FileUploadPDF" runat="server" Enabled="False" /> </asp:Panel> </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView> Thanks, Jack. hi Jack, since your control is a child control of the loginview control, you
cant access it directly. You need to use the findcontrol method on your loginview control and get a reference to the checkbox contained in the contenttemplate. for eg. c# CheckBox cb1 = (CheckBox)LoginView1.FindControl("MyCheckBox"); if (cb1 != null) // do something with cb1 vb.net Dim cb1 AS CheckBox = CType(LoginView1.FindControl("MyCheckBox"), CheckBox) if (cb1 IsNot Nothing) then 'Lets do something end if Regards, Alessandro Zifiglio http://www.AsyncUI.net Show quoteHide quote "Jack" <jack@nospam.com.uk> ha scritto nel messaggio news:44a90959$1@quokka.wn.com.au... > Hello, > > After I moved my Checkbox control 'inside' a <asp:LoginView />, my > code-behind file isn't compiling saying that: > > "The name 'MyCheckbox' does not not exist in the current context." > > Basically, when the 'administrator', and only the administrator, logs into > the site (from another page), I want him to check a checkbox on this page. > It all worked fine with anonymous access before (without the username and > roles set up). I'm not too sure why one shouldn't access the ASP controls > from code. > > How can my code-behind file access ASP.NET 2.0 controls on my webpage when > the controls are embedded inside a <asp:LoginView> ? > > It looks like this: > > <asp:LoginView ID="LoginView1" runat="server"> > <AnonymousTemplate> > Anonymous template here... > </AnonymousTemplate> > > <RoleGroups> > <asp:RoleGroup Roles="Administrator"> > <ContentTemplate> > > <asp:LoginStatus ID="LoginStatus" > runat="server" LogoutImageUrl="Graphics/logout.jpg" Visible="false" /> > > <asp:Button ID="ButtonInsertNew" runat="server" > Text="Insert New" OnClick="ButtonInsertNew_Click" /> > <asp:Label ID="LabelError" runat="server" > ForeColor="Red" Width="625px"></asp:Label> > > <asp:Panel ID="PanelFileUpload" runat="server" > > <asp:CheckBox ID="CheckBoxPDF" runat="server" > AutoPostBack="True" > > OnCheckedChanged="CheckBoxPDF_CheckedChanged" > Text="PDF Filename" Width="125" /> > <asp:FileUpload ID="FileUploadPDF" > runat="server" Enabled="False" /> > </asp:Panel> > > </ContentTemplate> > </asp:RoleGroup> > > </RoleGroups> > </asp:LoginView> > > > Thanks, > Jack. > >
Wizard control in 2.0 and dynamic items
Passing values to user controls - naughty problem Why it doesn't work? web controls install is this possible? Interrogating cells on current row for GridView CheckBoxList Control column width Best way to save properties (ie. text) on webcontrols for reloading (asp.net 2.0) Treeview Width. Using a custom server control declaratively in a user control |
|||||||||||||||||||||||