473,624 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Src Rather Than CodeBehind in Web User Controls

I've read that in the Page Directive of an aspx page, changing the
CodeBehind attribute to Src saves you from having to compile the page before
refreshing. This is preferable in a large development environment where
rather than having each developer running a local copy of a website, they
can make changes simultaneously to a central web server without stepping on
each other's toes as far as compilation is concerned.

ANYWAY, this is fine for aspx files, but when you try this with ascx files
(user controls), I get the following error:

The base class includes the field 'uc', but its type
(TestWeb.WebUse rControl1) is not compatible with the type of control
(ASP.WebUserCon trol1_ascx).

It seems to be having a problem with the declaration of the user control on
the CodeBehind of the containing aspx page. When I remove it, it works
fine. But then I can't really do anything with it programmaticall y.

Does anyone know how to make it work so that I can declare and manipulate
the user control in the CodeBehind under these circumstances?

HERE'S THE ASPX PAGE:
<%@ Page Language="vb" AutoEventWireup ="false" Src="WebForm1.a spx.vb"
Inherits="WebFo rm1"%>
<%@ Register TagPrefix="uc1" TagName="WebUse rControl1"
Src="WebUserCon trol1.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body>
<form id="Form1" method="post" runat="server">
<uc1:WebUserCon trol1 id=uc runat="server"
txt="source"></uc1:WebUserCont rol1>
</form>
</body>
</html>

I ADDED THE FOLLOWING DECLARATION TO THE "Web Form Designer Generated Code"
REGION OF THE ASPX CODEBEHIND:
Protected WithEvents uc As WebUserControl1

HERE'S THE USER CONTROL:
<%@ Control Language="vb" AutoEventWireup ="false"
Src="WebUserCon trol1.ascx.vb" Inherits="WebUs erControl1"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<span>Santa Clause doesn't exist.</span>
Thanks,
Nehal
Nov 17 '05 #1
6 1780
Hi Nehal,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue and researching it now. More time is needed.
I will update you as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #2
Hi Nehal,

I am sorry if there is any misunderstandin g.

As I understand, what your concern is that when you use the following
syntax to register a user control inside a consumer aspx page, an error
occurred.

<%@ Register TagPrefix="uc1" TagName="WebUse rControl1"
Src="WebUserCon trol1.ascx" %>

However, if you change the property name of "Src" to "codebehind ", it works
ok. However with the "codebehind " syntax, you cannot declare an instance of
the user control in code-behind of the consuming aspx, right? Please
correct me if I am wrong.

I created a user control and tried to drag it onto an aspx page. It was
noticed that by default, the "src" was used.

<%@ Register TagPrefix="uc1" TagName="calend ar" Src="calendar.a scx" %>

and I also declared a variable to point to the user control

Protected uc As calendar ' calendar is the class of my user control

And in the Init event of the consuming aspx page, I used the following code
to bind the uc variable to the user control on this aspx.

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()

uc = Me.FindControl( "Calendar1" )
AddHandler uc.Load, uc_Load()
End Sub

Private Function uc_Load()

End Function

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #3
Actually, the problem lies in changing CodeBehind to Src in control
directive at the top of WebUserControl1 .ascx:

<%@ Control Language="vb" AutoEventWireup ="false"
Src="WebUserCon trol1.ascx.vb" Inherits="WebUs erControl1"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>

"Jacob Yang [MSFT]" <ji***@online.m icrosoft.com> wrote in message
news:jv******** ******@cpmsftng xa06.phx.gbl...
Hi Nehal,

I am sorry if there is any misunderstandin g.

As I understand, what your concern is that when you use the following
syntax to register a user control inside a consumer aspx page, an error
occurred.

<%@ Register TagPrefix="uc1" TagName="WebUse rControl1"
Src="WebUserCon trol1.ascx" %>

However, if you change the property name of "Src" to "codebehind ", it works ok. However with the "codebehind " syntax, you cannot declare an instance of the user control in code-behind of the consuming aspx, right? Please
correct me if I am wrong.

I created a user control and tried to drag it onto an aspx page. It was
noticed that by default, the "src" was used.

<%@ Register TagPrefix="uc1" TagName="calend ar" Src="calendar.a scx" %>

and I also declared a variable to point to the user control

Protected uc As calendar ' calendar is the class of my user control

And in the Init event of the consuming aspx page, I used the following code to bind the uc variable to the user control on this aspx.

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()

uc = Me.FindControl( "Calendar1" )
AddHandler uc.Load, uc_Load()
End Sub

Private Function uc_Load()

End Function

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4
Hi Nehal,

I have done a lot of research regarding this issue. Based on my research
and experience, this issue is by design.

The reason is that after changing all the "CodeBehind =" to "Src=", I got
the following error when I closed and reopened the solution.

"...The @Page or @Control directive contains a src= attribute, which is not
supported in Visual Studio..."

I am using VS.NET 2003.

Please let me know if it makes sense.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5
Yes, Visual Studio.NET doesn't like it, but it still works as far as
aspnet_wp is concerned. CodeBehind is an attribute used only by the IDE to
build the solution. I'm using VS.NET too, but I just ignore the error
message. Maybe it'll be fixed in Whidbey...

"Jacob Yang [MSFT]" <ji***@online.m icrosoft.com> wrote in message
news:PL******** ******@cpmsftng xa06.phx.gbl...
Hi Nehal,

I have done a lot of research regarding this issue. Based on my research
and experience, this issue is by design.

The reason is that after changing all the "CodeBehind =" to "Src=", I got
the following error when I closed and reopened the solution.

"...The @Page or @Control directive contains a src= attribute, which is not supported in Visual Studio..."

I am using VS.NET 2003.

Please let me know if it makes sense.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #6
Hi Nehal,

I cannot guarantee if this issue will be changed in Windbey. It is
determined by the product team. Thank you for your understanding.

You can send the feedback of our products to Microsoft directly. Please
refer to the following URL.

Contact Microsoft
http://support.microsoft.com/default.aspx?pr=cntactms
"...
Microsoft Wish

Make a product suggestion or feature request. Product enhancement
suggestions can include:
Improvements on existing products
Suggestions for additional features
Ways to make our products easier to use
..."

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7

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

Similar topics

4
2408
by: Boban Dragojlovic | last post by:
I create a new webform (I always use codebehind), and I insert some server-side controls into the form (the ASPX) Later, I switch to codeview, and I notice that some (sometimes all) of the controls I created have been automatically defined for me in the #Region " Web Form Designer Generated Code " section Later, when I add more controls this no longer happens. First, I'm wondering which of my actions causes it to no longer do this;
3
1578
by: nevets2001uk | last post by:
Hi. I've just started my second ASP.NET (VB) app and I'm using codebehind this time. I'm not using visual studio but am instead coding it all in notepad (HTML, ASP.NET and CSS) I'm trying to understand how to best use codebehind to do what I want to achieve. Basically, so far I have a codebehind file for one page which works as I wanted but I want other pages to share that codebehind file. That's no problem except I want each one to...
5
3150
by: Marcel Gelijk | last post by:
Hi, I am trying to create a User Control that is located in a seperate class library. The User Control contains a textbox and a button. The page generates an exception when it tries to access the code variable that are supposed to be linked to the contained controls. It runs fines when everything is contained in a single web form project. What do I need to do to make it work from a class library?
2
1857
by: crjunk | last post by:
I have a droped a UserControl named "ReceivedRecord1" onto my web form. Currently, I have been saving information typed in by the user with the following code that is located in the CodeBehind page of my Web Form. For Each ctrl In Page.FindControl("ReceivedRecord1").Controls If TypeOf (ctrl) Is TextBox Then ' yada yada yada End If Next
12
2238
by: Wardeaux | last post by:
All, Wanting to find a way to create web pages to add to my website without having to recompile the codebehind everytime I want to add a new one... Here's the deal: I have a web app that takes work orders for 7 different items, each item gets 1 page for input specs. All works well. I want to add a new item. I do not want to recompile and redistribute my app everytime just to add a new input page. Can ASPX resources be compiled into a...
0
1226
by: Tigrou | last post by:
Hello, I'm searching for a solution who permit me to create an TemplateColumn in a DataGrid into codebehind... I found only solution for create it into the ASPX code... My problem is to find a solution for add ImageButton controls into this column, for now my code is: Dim colSupp As New TemplateColumn
2
3118
by: Tigrou | last post by:
Hello, I'm searching for a solution who permit me to create an TemplateColumn in a DataGrid into codebehind... I found only solution for create it into the ASPX code... My problem is to find a solution for add ImageButton controls into this column, for now my code is: Dim colSupp As New TemplateColumn
12
2195
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...
10
2412
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
8240
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
8680
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
8625
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...
0
8482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4082
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...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
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
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
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.