Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Can't access webpage's controls from the code-behind file after putting it in a <asp:LoginView/>

Reply
Thread Tools

Can't access webpage's controls from the code-behind file after putting it in a <asp:LoginView/>

 
 
Jack
Guest
Posts: n/a
 
      07-03-2006
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>

<aspanel 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" />
</aspanel>

</ContentTemplate>
</asp:RoleGroup>

</RoleGroups>
</asp:LoginView>


Thanks,
Jack.


 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      07-03-2006
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
"Jack" <> ha scritto nel messaggio
news:44a90959$...
> 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>
>
> <aspanel 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" />
> </aspanel>
>
> </ContentTemplate>
> </asp:RoleGroup>
>
> </RoleGroups>
> </asp:LoginView>
>
>
> Thanks,
> Jack.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
putting user controls on a page manually Sunfire ASP .Net 2 11-06-2007 02:46 PM
Putting user controls inside a templated DataList (ASP 2.0) Roger Helliwell ASP .Net Web Controls 3 10-31-2004 11:15 PM
wxSizer: Define sizer hierarchie before putting controls in or vice versa? Piet Python 2 09-10-2004 01:44 PM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM
IE 6 freezes after putting text in form John Smith Computer Support 0 01-22-2004 11:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57