Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Common functionality across pages, what's the best solution?

Reply
Thread Tools

Common functionality across pages, what's the best solution?

 
 
Allan Ebdrup
Guest
Posts: n/a
 
      01-13-2006
Hi
I've created a asp.net 2.0 page with an Page_Init eventhandler that I want
to share among multiple pages, what's the best approach for this? Should I
inherit from the page, or is it better to create a library with the
eventhandler code and insert a call to the library on Page_Init on all pages
that should implement this feature?
I would also like to be able to create maste pages that support the same
functionality.

Kind Regards,
Allan Ebdrup


 
Reply With Quote
 
 
 
 
Dan
Guest
Posts: n/a
 
      01-13-2006
Its difficult to advise without knowing what your pageinit is doing.

For example if you are just setting a load of variables to starting values
then there are a few ways, you could store these contants in an xml file and
read those vars in on application start?

Can you provide some more info? Maybe some code of the pageinit method.

--
Dan
"Allan Ebdrup" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
> I've created a asp.net 2.0 page with an Page_Init eventhandler that I want
> to share among multiple pages, what's the best approach for this? Should I
> inherit from the page, or is it better to create a library with the
> eventhandler code and insert a call to the library on Page_Init on all
> pages that should implement this feature?
> I would also like to be able to create maste pages that support the same
> functionality.
>
> Kind Regards,
> Allan Ebdrup
>



 
Reply With Quote
 
 
 
 
DavidG
Guest
Posts: n/a
 
      01-13-2006
I would put the handler in a class in the app_code folder and use a
delegate in the page_init handlers on the page to call the shared
handler function

HTH

-----------------------------------------
David Gray
ASP.NET/C# Developer/Architect (MCAD.NET)

On Fri, 13 Jan 2006 11:03:18 +0100, "Allan Ebdrup" <(E-Mail Removed)>
wrote:

>Hi
>I've created a asp.net 2.0 page with an Page_Init eventhandler that I want
>to share among multiple pages, what's the best approach for this? Should I
>inherit from the page, or is it better to create a library with the
>eventhandler code and insert a call to the library on Page_Init on all pages
>that should implement this feature?
>I would also like to be able to create maste pages that support the same
>functionality.
>
>Kind Regards,
>Allan Ebdrup
>

 
Reply With Quote
 
Allan Ebdrup
Guest
Posts: n/a
 
      01-13-2006
The page Init swaps some controls if there is a special control defined
instead:
---
protected void Page_Init(object sender, EventArgs e)
{
int intPartner = System.Convert.ToInt32(Request["partner"]);
if (intPartner > 0)
{
CheckControlsForSwap(intPartner, Page.Controls);
}
}
protected void CheckControlsForSwap(int intPartner, ControlCollection
controlCollection)
{
foreach (Control c in controlCollection)
{
//Response.Write("c.GetType:" + c.GetType().ToString() + "<br>");
if (c.GetType().ToString().Substring(0, 13) == "ASP.controls_")
{
/* convert a string like "ASP.controls_default_dynamicload_ascx" to:
* "controls/partner/[partnerid]/dynamicload.ascx"
*/
string strControlPath = c.GetType().ToString();
//check that this is not already a partner specific control
if (strControlPath.IndexOf(intPartner.ToString()) == -1)
{
strControlPath = strControlPath.Replace("ASP.", "");
strControlPath = strControlPath.Replace("_ascx", ".ascx");
strControlPath = strControlPath.Replace("default", "partner/" +
intPartner.ToString());
strControlPath = strControlPath.Replace("_", "/");
//load partner control
Control partnerControl = null;
bool blnLoaded = true;
try
{
partnerControl = Page.LoadControl(strControlPath);
}
catch (System.Web.HttpException)
{
blnLoaded = false;
}
if (blnLoaded)
{
//we have loaded a partner specific control and want to swap it with
hte default control
int intControlIndex = controlCollection.IndexOf(c);
//remove the default control
controlCollection.Remove(c);
//add partner control
controlCollection.AddAt(intControlIndex, partnerControl);
//call CheckControlsForSwap on the same collection again to swap other
controls in this collection
CheckControlsForSwap(intPartner, controlCollection);
//return because the enumerater can't continue when we've added and
removed controls from the collection
return;
}
}
}
if (c.HasControls()) CheckControlsForSwap(intPartner, c.Controls);
}
}
---

This works fine when I run it directly in a page, but when using a maste
page the Request["partner"] is empty even though the master page contains a
dropdownlist with the ID "partner" that isn't empty.

Kind Regards,
Allan Ebdrup


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
User control multiple instances in page + common javascript functionality Anirudha24.d ASP .Net 0 02-08-2011 05:03 AM
java.lang.NoSuchMethodError: wm.common.session.Common.getCustRptListFromMax Denny Java 1 05-01-2008 07:33 AM
Common objects across a user control Josh Schmidt ASP .Net Web Controls 1 11-09-2006 07:50 PM
Common Login page across multiple web applications on the same domain ngodugu@gmail.com ASP .Net 1 02-17-2005 09:21 PM



Advertisments