473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

.ascx files

Hi all,

I have just put together our organisations 'template' for our web
applications and have created 7 .ascx files which when dropped into my
template file work perfectly...however, I have a question...

As our team develops several applications I wanted these generic .ascx's to
be able to be used by all - therefore I've placed them in the root of the
domain we work on in a directory called /WebUserControls

I noticed that the first line of the HTML for each is as follows :

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="Application.ascx.vb" _
Inherits="WebApplication1.Application"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

(please excuse the wrap around)

My understanding of the web user controls is limited, but I believe we can
benefit by these in the following areas :

shared code - no need to reproduce the common parts
cached - so that our pages load faster

In the above there is a reference to the 'WebApplication1' - which was the
name of the project I was working on (default one etc) in visual studio - is
this likely to cause a problem for using these controls? ie, their
applications - which wont be called WebApplication1 will not work with
these? If so - how do I get around this so that we can all point to the
..ascx's in the central location and not all take copies of them etc??

Any information would be appreciated - sorry if some of this doesn't make a
lot of sense - I'm not 100% clued up on .Net yet - so plenty of learning as
I go etc...

Regards

Rob
Nov 18 '05 #1
4 2488
"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
In the above there is a reference to the 'WebApplication1' - which was the
name of the project I was working on (default one etc) in visual studio - is this likely to cause a problem for using these controls? ie, their
applications - which wont be called WebApplication1 will not work with
these? If so - how do I get around this so that we can all point to the
.ascx's in the central location and not all take copies of them etc??

Any information would be appreciated - sorry if some of this doesn't make a lot of sense - I'm not 100% clued up on .Net yet - so plenty of learning as I go etc...


Yeah, unfortunately, unless your entire web site is one big asp.net project,
you need to make a local copy of the ascx files. It's not quite the same
thing in scope as an include file in that sense (although ascx are language
neutral.) I've tried to get around this too. We rely on good versioning
controls to try and prevent regression problems, etc.

R.
Nov 18 '05 #2
"Richard K Bethell" wrote ...
Yeah, unfortunately, unless your entire web site is one big asp.net project, you need to make a local copy of the ascx files. It's not quite the same
thing in scope as an include file in that sense (although ascx are language neutral.) I've tried to get around this too. We rely on good versioning
controls to try and prevent regression problems, etc.


Oh that completely blows! Not your reply - just the lack of reusability
which is all I ever see mentioned about .Net!

This is really a pain in the arse for us now - as it means that our entire
template file which I was hoping to enable all of our developers to simply
grab and it would work fine means that now when they copy it across there is
more chance of bits and pieces being changed, either on purpose or by
accident, and that it will be still a case of having to change EVERY
application if we just want to change one item in the template....

Fek... :o(

Regards

Rob
Nov 18 '05 #3
Rob, instead of using user web controls (ascx) try using user composite
controls or rendered controls. composite controls are easier to code than
rendered controls(in which you build the control from ground up). They are
made of existing .net web controls. When built, it will create an assembly
(a dll file) which you can use in all your applications. In that one dll
file you can keep all your user controls and you can even put them in your
toolbox.

Onur

Nov 18 '05 #4
In article <OW**************@TK2MSFTNGP11.phx.gbl>,
ro**********@NOSPAMubht.swest.nhs.uk says...
"Richard K Bethell" wrote ...
Yeah, unfortunately, unless your entire web site is one big asp.net

project,
you need to make a local copy of the ascx files. It's not quite the same
thing in scope as an include file in that sense (although ascx are

language
neutral.) I've tried to get around this too. We rely on good versioning
controls to try and prevent regression problems, etc.


Oh that completely blows! Not your reply - just the lack of reusability
which is all I ever see mentioned about .Net!

This is really a pain in the arse for us now - as it means that our entire
template file which I was hoping to enable all of our developers to simply
grab and it would work fine means that now when they copy it across there is
more chance of bits and pieces being changed, either on purpose or by
accident, and that it will be still a case of having to change EVERY
application if we just want to change one item in the template....

Fek... :o(

Regards

Rob

Hi Rob,

What I have done is created a C# Assembly with a "Shell" Class that
opens template files. I can use this once class on every page, even
through sub directories and it works perfect. I use it on just about
every site I have in ASP.Net.

Below is some snippets form the class I have writte (minus namespace
info):

[ParseChildren(false)]
public class Shell : System.Web.UI.WebControls.WebControl
{
string _title = "";
BaseClasses _base = new BaseClasses(); // This is a class
I use for all my functions that I have to have across almost every
control I develop. The most used one is the GetCtlPrefix() which I have
included after this class

public string Title
{
get
{
return _title;
}

set
{
_title = value;
}
}

System.Web.UI.WebControls.Literal c_title;
protected override void Render(HtmlTextWriter output)
{

Control _ts = new Control();
_ts = Page.LoadControl(_base.GetCtlPrefix() +
"controls/topshell.ascx");

// This will find the <ASP:literal> control in the
topshell.ascx file and change it's value
c_title = (System.Web.UI.WebControls.Literal)
_ts.FindControl("title");
c_title.Text = _title;

_ts.RenderControl(output);
Control _bs = new Control();
_bs = Page.LoadControl(_base.GetCtlPrefix() +
"controls/bottomshell.ascx");
_bs.RenderControl(output);

}
}
public class BaseClasses
{

public string GetCtlPrefix()
{
string _script =
HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString();
char[] _scriptProc = _script.ToCharArray();
int dir = 0;
string _ctlPrefix = "";
for (dir = 1; dir < _script.Length; dir++)
{
if(_scriptProc[dir].ToString() == "/")
{
_ctlPrefix += "../";
}
}

return _ctlPrefix;
}
}

Using the combination of these two classes will enable you to create a
custom control that can be accessed by any page in you application. To
set your app up, you will need to do a couple of things first:

1. Make a 'controls' directory in your main application directory to put
the .ascx file in. I had code all of my ascx files in Dreamweaver or
some other text editor with no code behind features. I personally find
that it seems to work better that way. You won't have to worry about
these files being open to the public because IIS will not serve those
files directly.

2. Create the topshell.ascx and bottomshell.ascx files and put them in
the controls directory. To make the Title part work you will want to
include this in your topshell.ascx:

<head>
<title><asp:Literal id="title" runat="server" /></title>
</head>

The class will look for this when rendering the topshell.ascx file.

3. Create your aspx pages with the new "Shell" server control:

<%@ Register TagPrefix="Ctrl" Namespace="YourControlsNamespace"
Assembly="YourControlsAssemblyName" %>

<Ctrl:Shell Title="The title of this page" runat="server">

You can now put any content you want in between these tags,
including other ASP.Net or custom server tags. THe key to this is the
"[ParseChildren(false)]" section above the class.

</Ctrl:Shell>

In addition to the title, you can also add your meta content. I use
ascx files for all of my menus and have a section in mine where I list
the menus and what order I want them displayed and they are put there.

Please note! This will only really work if you handcode your pages. If
you use the VS.Net desinger or WebMatrix, this will not work correctly
without modifiying the html source to make sure everything lines up.
But the beauty of this system is that as long as the topshell.ascx files
and bottomshell.ascx files are present, you can use this in any
application simply by copying the control dll to the bin directory.
Like I said, I use this on almost every site I have done in ASP.Net and
it works like a charm.

If you need to use VS.Net I would probably wait for version 2 with the
master pages feature. You could use this system, but it would be a
pain.

Let me know if you have any questions or have problems implementing it.

Dane Morgridge
Web/Software Developer
_____________________________
DTM Technologies
http://www.dtmtechnologies.net


Nov 18 '05 #5

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

Similar topics

1
by: kbailey | last post by:
what a waste of money. visual studio does not handle user control files - these are files with and ascx extension are are refered to in the help as 'user-authored server controls'. the VS...
2
by: Wade Beasley | last post by:
I have a web project that currently has a standard header, footer, and menu ascx files. I am now suppose to change the project to allow a user to choose from 3 different views, ie 3 different...
4
by: ChrisB | last post by:
Hi - I'm just trying to figure out what would be involved with deploying a simple HTML update to an ASCX file. Where there were no changes to the code behind (compiled code), to deploy this to...
6
by: tshad | last post by:
I have an ascx file I am using to include my logos and heading information for all my pages. It was working fine up until now. I decided to set up an admin folder inside of my main folder and...
6
by: Martin Eyles | last post by:
Hi, I have a .aspx page which has a .ascx file included through the lines <%@ Register TagPrefix="aspcustom" TagName="menu" Src="Menu.ascx" %> and <aspcustom:menu id="Menu1"...
0
by: damiensawyer | last post by:
Hello all, I'm very new to all of this. I have a theme and a skin (the standard ones). I have a standard master page which is holding a custom ascx which has a treeview in it. Can someone...
3
by: Steven Nagy | last post by:
Hi all, ASP.NET : Framework 2.0 - C# A recent addition to my code generater will create GridView's and ObjectDataSource's in a control (ASCX). So the code gen creates an ascx, ascx.cs,...
0
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have an ascx file that dynamically loads other ascx files. each of these ascx files need to perform client callback functions. It seems that when i try and break out all the javascript code into...
11
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a machine Windows Server 2003 using IIS 6.0 and I am getting the error BC30560 prjob_ascx is ambiguous in the namespace ASP I found a fix. Deleting all the files in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.