Events in System.Web.UI.Page

J

james

Hey Guys,

Is there any way to attach to the onLoad property of a page, outside
of the page itself?

In porting an application from jsp to aspx, I added attributes like

<script runat="server">
/** @attribute useBean() */
/** @attribute setProperty("*") */
SampleBean testing;

void Page_Load()
{
new JspEmulator().reflect(this);
}
</script>

I would like to remove the Page_Load event, since this happens for all
pages. I looked at global.asax and did not see a way to reference the
page instance.

Thanks,
James
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Not that I know of.

You can make the event public simply by writing a wrap around it. but the
question is, who is going to subscribe to it?

Beside, I do not quite understand what you are trying to do inthe first
place, could you elaborate please?
 
J

james

Hi Ignacio,

Sorry for being unclear. Since global.asax has access to Session,
Request, etc. I was hoping I could also access Page and attach its
onLoad event.

Also that code is J#, so the /** @attribute useBean() */ syntax is
equal to [useBean()] in C#.

What I am trying to do is use custom attributes to initialize
variables on startup. The attributes don't do anything on their own,
so currently the Page has to make a call to get things started (in
this case to jspEmulator.reflect). For instance, a useBean attribute
results in

void useBean(useBeanAttribute attr, FieldInfo field, Page page)
{
// pull bean from session or create a new instance
field.SetValue(page, page.Session[field.Name] ??
Activator.CreateInstance(field.FieldType));

// store the bean on exit
page.SaveStateComplete += delegate(object sender, EventArgs e)
{
page.Session[field.Name] = field.GetValue(page);
};
}

I'm just trying to cut out the redundant code. Any other ideas would
be appreciated.

Thanks,
James
 

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

Top