asp.net user control

E

edsuslen

I am trying to migrate from asp to asp.net and having problem replacing
include with user control.
On every page we have include asp that have some common asp code that I
need to run before the page code kicks in, but user control code is
always running after the page code.
I am even registering and placing user control before my page
initialization, but still it's running after.

<%@Register TagPrefix="FindSessionUC" TagName="FindSession"
Src="EDWFindSessionValues.ascx"%>
<FindSessionUC:FindSession id="MyFindSessionUC" runat="server" />


<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="EDW_TEST.aspx.vb" Inherits="CSATodayWEBNet.EDW_TEST"%>

What am I doing wrong?
Any help would be appritiated.
Thanks.
 
M

mnichols

Hi,

I suggest you put breakpoints in your user contol and in your aspx page
to get an idea of the order in which events are occurring.

Also, it is unclear whether your code is supposed to execute javascript
or c#/vb code.

The location of your <FindSessionUC> tage doesn't determine when code is
executed instead it determines where the rendered code is placed within
the html markup that is output.

To simulate ASP like behaviour (a habit I am also used to) I use the
following at the top of my aspx page:

<!--#Include virtual="~/tools/PageHeader.inc" -->

But even then I know the code will be executed/included after the
PageLoad event.

I think that if you need code routinely executed before the Page_Load
event you are best off writing a new class that inherits
System.Web.UI.Page and then using it for all of your pages. That is
something I also do.

In ASP.NET 2.0 I think something similar can be done with Master pages.

Hope this helps a bit.

mnichols
 
J

john_teague

Another option would be to put the code into a class that inherits from
Page and have your code behind class inherit from your new "base page".
Now you can use all of the events from the page, like OnLoad, Init,
etc...

I would use a user control only for content you want to use in multiple
pages in your site.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top