473,805 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.Net 2.0 b2 + Web UserControl

I upgraded a VB.Net 1.1 project to 2.0b2 and now I can't seem to figure out
how to fix my user controls. I have a user control named SecurityControl
that contains a few static methods and properties (as well as instance
methods and properties). Now that I've upgraded the project to 2.0b2, my
User Controls can't be accessed from the new App_Code files (my code files
from before the upgrade). I've tried to do the same thing with a new web
application project, but still no luck. How can I write the following from
within a "Module" that is under App_Code?

App_Code\Common .vb:

Public Function SomeTestMethod( ) As Boolean
' Some validation or something here...

' Check security.
Return SecurityControl .IsInRole("MyRo leName")
End Function
In SecurityControl .ascx.vb:

Public Shared Function IsInRole(ByVal Role As String) As Boolean
' Do some error checking before the following call.
Return Thread.CurrentP rincipal.IsInRo le(Role)
End Function
Thanks in advance,
Mythran

Nov 19 '05 #1
4 1276
If the code in the .vb file in App_Code is in a class definition, then it
should all be ok -- ASP.NET will compile the .vb file for you and the resultant
assembly should be accessible from all of your pages.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I upgraded a VB.Net 1.1 project to 2.0b2 and now I can't seem to
figure out how to fix my user controls. I have a user control named
SecurityControl that contains a few static methods and properties (as
well as instance methods and properties). Now that I've upgraded the
project to 2.0b2, my User Controls can't be accessed from the new
App_Code files (my code files from before the upgrade). I've tried to
do the same thing with a new web application project, but still no
luck. How can I write the following from within a "Module" that is
under App_Code?

App_Code\Common .vb:

Public Function SomeTestMethod( ) As Boolean
' Some validation or something here...
' Check security.
Return SecurityControl .IsInRole("MyRo leName")
End Function
In SecurityControl .ascx.vb:

Public Shared Function IsInRole(ByVal Role As String) As Boolean
' Do some error checking before the following call.
Return Thread.CurrentP rincipal.IsInRo le(Role)
End Function
Thanks in advance,
Mythran


Nov 19 '05 #2

"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:85******** **************@ msnews.microsof t.com...
If the code in the .vb file in App_Code is in a class definition, then it
should all be ok -- ASP.NET will compile the .vb file for you and the
resultant assembly should be accessible from all of your pages.

-Brock
DevelopMentor
http://staff.develop.com/ballen


No...

The UserControl is called SecurityControl . The .vb file for this is NOT in
the App_Code section. It's under the SecurityControl .ascx file (associated
code-behind for the UserControl). It is in a class definition, for the user
control, but not under App_Code...that 's how UserControls work. Why they
split the code into App_Code, I have no idea. It makes it more complex than
it used to be and now code in the same project gets split off into two
assemblies!?! What were they thinking?

Mythran

Nov 19 '05 #3
> No...

The UserControl is called SecurityControl . The .vb file for this is
NOT in the App_Code section. It's under the SecurityControl .ascx file
(associated code-behind for the UserControl). It is in a class
definition, for the user control, but not under App_Code...that 's how
UserControls work. Why they split the code into App_Code, I have no
idea. It makes it more complex than it used to be and now code in the
same project gets split off into two assemblies!?! What were they
thinking?


Ok, in that case if you need to access the shared methods on your ASCX from
another page or control, add the Reference dirctive:

<%@ Reference Control="~/SecurityControl .ascx" %>

If you need to access it from code in App_Code, then you will have problems
as App_Code is compiled prior to your ASPXs and ASCXs, so you'll have chicken
and the egg problem. I'd argue that putting shared method in an ASCX is probabaly
not the best idea, primarily for this ordering problem. If you did put those
non-control specific shared method into App_Code, then, as I previously posted,
this should work fine.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #4

"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:86******** **************@ msnews.microsof t.com...
No...

The UserControl is called SecurityControl . The .vb file for this is
NOT in the App_Code section. It's under the SecurityControl .ascx file
(associated code-behind for the UserControl). It is in a class
definition, for the user control, but not under App_Code...that 's how
UserControls work. Why they split the code into App_Code, I have no
idea. It makes it more complex than it used to be and now code in the
same project gets split off into two assemblies!?! What were they
thinking?


Ok, in that case if you need to access the shared methods on your ASCX
from another page or control, add the Reference dirctive:

<%@ Reference Control="~/SecurityControl .ascx" %>

If you need to access it from code in App_Code, then you will have
problems as App_Code is compiled prior to your ASPXs and ASCXs, so you'll
have chicken and the egg problem. I'd argue that putting shared method in
an ASCX is probabaly not the best idea, primarily for this ordering
problem. If you did put those non-control specific shared method into
App_Code, then, as I previously posted, this should work fine.

-Brock
DevelopMentor
http://staff.develop.com/ballen


lol, nice, chicken and egg...

Christian pov: The egg is the chicken's way of procreating.
Evolution pov: The chicken is the egg's way of procreating.

:)

Anywho, thanks for your help. The exact problem in ASP.Net 1.1, we have the
following setup:

~/controls/SecurityControl .ascx (with ~/controls/SecurityControl .vb)
~/classes/Common.vb (contains code that may call the shared methods of
SecurityControl ).
When upgraded the project to ASP.Net in 2.0b2 it breaks it ... new structure
is like:

App_Code/classes/Common.vb
~/controls/SecurityControl .ascx (with ~/controls/SecurityControl .vb)

So, common can no longer call SecurityControl .IsInRole or any other
property/method that is shared on SecurityControl at all? That stinks!
heh...

Thanks anyways..

Mythran

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7127
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to be able to drag-and-drop to the treeview from outside the UserControl. Now, when I drag over the treeview in the UserControl, the UserControl gets the drag-and-drop events, but the treeview doesn't. Is there a simple way to pass drag-and-drop...
8
1961
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for that category, the results are paged 10 to a page and the user can page them. As this "Category" usercontrol hardly ever changes I wanted to setup up caching for it. However I realised that when the user clicks a ctageory it is selected and...
2
2248
by: Eric Maia | last post by:
I have two UserControls I am using in a form. These are each also used separately in two other forms. The structure is essentially this: CourseUserControl.ascx - select or enter a course SessionUserControl.ascx - select or enter a course session CourseDetails.aspx - a form which contains just CourseUserControl CourseSessionDetails.aspx - a form which contains just SessionUserControl TrainingRequestDetails.aspx - a form which includes...
2
4635
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation for me! I apologize for the length of this posting, but I wanted to make sure that I get an answer other than "Hey man, just use LoadControl!", because this is not what I want. The Task: Isolate a collection of web forms which are created as
41
4338
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
12
2217
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
9
14469
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing...
5
19711
by: Blue | last post by:
We have a custom word processing type editor built with C# and .NET 2.0 and we need to support typing in languages other than English. I want to be able to use the Windows IME to enter in text similar to how it works in a text box. For example, if I put focus on a TextBox and then switch my language on the language bar to Japanese or Chinese, several buttons appear on the language bar including Input Mode, Input Style, Conversion Mode,...
6
12144
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use binding like normal. The problem I am running into is that my UserControl ends up with a different BindingContext then the ParentForm it is contained in and thus all other controls on the parent form. (I want various controls on the form to...
10
2432
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's my question. Once the UserControl is dropped onto the container page, how can I perform some action on the codebehind of the container page from the codebehind of the UserControl? For instance, suppose that the UserControl is dropped inside one...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.