Handling Master Page Panels with Base Control Class - c#

I have admin module. This module have one master page which has the no of panels at left side. I have to make this panels visible and invisible with base control class which is constructed in VB language. I'm working with asp.net 2.0 with c# web site.
Please give me idea how do i construct this base control class and manage panels with Master Page on link button click event.

We'll there is a plenty of opportunities to make it.
I'd prefer using of facade pattern.
Construct a class which would use VB class inside:
public newManageClass()
{
private oldManagedVBClass _old;
//.ctor
public newManageClass()
{
_old = new oldManagedVBClass();
}
public void makePanelsVisible()
{
_old.MakePanelsVisible();
}
}
And then you can use this class inside your master page as helper class.

Related

Access Web Methods from multiple aspx pages

I have a user control which is used in multiple(4 to be exact) aspx pages. This usercontrol have a couple of Get/Save webmethods. Right now, I placed all the webmethods in one aspx page and kept calling the same ones from my javascript. I would like to place them in a central location that all the aspx pages can see, but not sure how/where. Any suggestions please?
Edit:
I know the WebMethods should be a part of a class inherited from 'System.Web.UI.Page'. Is there a better place that I can move these methods to, where js can call from.
try to creating Generic Handler (.ahx) and put all your code there.
or try to creating base page, where the base page inherited with the all the aspx pages
in your aspx page :
public partial class RekapDocumentView : based.PageBase
{
}
in your new class :
public class PageBase : System.Web.UI.Page
{
//your webmethods
}
perhaps this can help
If you try to create a class, VS will ask you if you wont to create a folder for it. All common classes should go in App_code folder. Then you can move your method in that class and reference them from the pages.
How about creating a web service which implements web methods that your user control needs to work properly.
Here is a MSDN article on this topic: http://msdn.microsoft.com/en-us/library/bb515101(v=vs.90).aspx
Hope this helps!
Regards,
Uros

Using the same code behind file for multiple .aspx pages

We are developing a site inside a CMS that pushed files to our production server. If the .apsx pages created share the same code behind file, will this cause a problem?
Why don't you let both pages inherit from the same class?
public class MyPage : System.Web.UI.Page
{
// common logic that both pages should have
protected void Page_Load(object sender, EventArgs e)
{
}
}
public partial class PageA : MyPage
{
// specific logic for page A
}
public partial class PageB : MyPage
{
// specific logic for page B
}
Yes. It is technically possible, but it is not a supported way of using ASP.NET and there will likely be gnarly difficulties with it.
You should use User Controls or AppCode instead.
I would suggest to avoid such design, so each page should has own code behind file.
Also take a look at the following ASP.NET features whcih can simplify sharing of common layout and behaviour across the web pages:
Master pages (.master), basically multiple pages which has the same layout could use a shared master page which provides the common layout and supporting code behind logic. Moreover - You can switch master pages in runtime and master pages could be nested, so Master Page could be placed inside of an other Master Page, this gives you a much of freedom and flexibility to design your web application layout and separate responsibilities as well.
User Controls (.ascx), it worth to separate concerns and split page by a set of controls, for instance, it could be LoginControl.ascx,, AdControl.ascx, SearhcControl.ascx, so you keep a code of page clean and each control provides specific functionality and own layout.
Inheritance, so basically set of pages have the same base class which inherited from the Page class (I would not suggest use this approach massively, one base page it is enough)
You may use other common development techniques like dependency injection to share code across multiple pages, this depends on particular case and business goals which were considered under the hood.

Accessing a master page public variable from user control

public partial class MasterPages_Main : System.Web.UI.MasterPage
{
public LoggedInUser ThisUser;
This is in my master page, and my user control is running on the page. In my user control however, I can't seem to reference ThisUser, do I have to pass it in to the control as a parameter? Is there any way to directly reference it?
Absolutely! Take a look at the methods and properties of an asp.net page. I've done similiar using:
HtmlForm mainform = (HtmlForm)Master.FindControl("form1");
Where the important part is the Master.FindControl();
This is a part of the Page class. Page.Master will get you to the master page of the current page.
I'm sure that there's some way to avoid passing an instance of LoggedInUser to your control, however it's probably best to pass it as a parameter as doing so promotes reuse of the control because it will be more loosely coupled.

Load template from user control

Im working with Sitefinity and I'm developing a Control Designer - however i dont think my question is specific to SiteFinity.
I have a class such as:
public class CaseStudyFeaturedItem : CaseStudySelectorControlDEsignerBase
The class it is inherriting from is itself inheriting from UserControl, like so:
public class CaseStudySelectorControlDesignerBase : System.Web.UI.UserControl {
Within CaseStudyFeaturedItem is it possible to load a template which is an embedded resource and then access the controls on that control?
So essentially, I have usercontrol.ascx which is an embedded resource so has a string like:
mynamespace.myclass.usercontrol.ascx;
And from within CaseStudyFeaturedItem I want to be able to load that usercontrol and then modify the controls (i.e. literals/labels) that are within it?
Is this possible?
Thanks
Al
We do this with every control in Sitefinity, but it would be a little complicated to do with your own custom controls (I assume you are using Sitefinity 3.7). The steps are the following:
- Implement a template container control, inheriting from GenericContainer:
protected class ItemListContainer : GenericContainer
{
public virtual Repeater RepeaterControl
{
get { return base.GetControl<Repeater>("repeater", true); }
}
}
- You need to get the template from the resource (use ControlUtils.GetTemplate method - Sitefinity does that for you):
public virtual ITemplate ItemListTemplate
{
get
{
if (itemListTemplate == null)
itemListTemplate = ControlUtils.GetTemplate(<virtual path to template>, <resource file name>,
<type to determine assembly for template>);
return itemListTemplate;
}
set
{
itemListTemplate = value;
}
}
- You need to call InstantiateIn method of the template, and pass it the container control
listContainer = new ItemListContainer();
ItemListTemplate.InstantiateIn(listContainer);
- Access all controls through the container
listContainer.RepeaterControl.DataBind();
In Sitefinity 4.0 we've included a base class for all controls, which will give you this functionality out of the box. In 3.7 though, you'll have to do all this by hand.
The ControlUtils class is in the Telerik.Framework.Web namespace. The code above is how this all is done in the ContentView control, you should probably make slight modifications depending on your case.
Cheers,
Slavo
The Sitefinity team # Telerik
Yes it is possible, but I'm not entirely sure what you're trying to accomplish based on your question. You can use LoadControl to dynamically load user controls. If you cast the result to the appropriate control type, you will then have access to all of its properties. From there, you can add it into whatever container you want to hold it. Is that the kind of thing you're trying to do?

How to make WPF Pages have common interface

We develop a wizard-like WPF application that has a Frame that navigates to various Pages. I define each Page in a separate xaml and xaml.cs file, and then have the application make the frame navigate between the page.
All of my pages currently inherit from Page. I would like to have a common interface to all my pages, so I can access them polymorphicly. However, changing the base class of the Page causes compilation to fail, as the files automatically generated by Visual Studio from the xaml file set the base class to Page, and I get an error that Partial declarations of must not specify different base classes.
One option I have is adding another interface (e.g. WizardPage) and make all the classes implement that interface, but that meas that each page need to implement all the intefaces functions, and this is inconvenient as I want most of the functions, for most of the pages, to have a default empty implementations.
Can you suggest other options I can use to address this?
Thasnkssplintor
You can make the root tag of your xaml to a class defined by you also.
Here you have to derive your base class from Page and then you can derive your page classes from your base class.
public class MyBaseClass : Page
{
.....
}
you can derive your page classes from a class like this:
public partial class MyDeriveClass : MyBaseClass
{
.............
}
and In your xaml write
<y:MyBaseClass y="add your Namesapace here" and add other attribute of Page also like default namespace and xmlns:x>
...............
</y:MyBaseClass>
Make a sort of adapter page that extends Page and implements WizardPage that provides empty implementations of the WizardPage Methods. Then make your other pages extend WizardPage.

Categories