Webforms - Best Way To Call A Presenter From Within A User Control?
Apr 4, 2011
I'm new to using the MVP pattern and I just want to make sure on the best way to call a presenter from within a user control.
MyPage.aspx has a presenter MyPresenter
The page contains a user control which accepts MyPage's Presenter via a property which I setup from MyPage
MyUserControl.Presenter = this.Presenter
I'm now trying to call Method1 within the presenter which retrieves some config and sets it on the view from the user control.
Presenter.Method1(); // calls method and sets config to the view
My question is firstly
should I be using the presenter in the user control in this way?
If so, is it valid to be accessing the view value via the user control as shown below.
Presenter.View.MyData
I just want to make sure I'm not going off down the completely wrong path with this!
View 1 Replies
Similar Messages:
Dec 16, 2010
I have an aspx page that I would like to have injected a reference to a user control. The user control is stored in a seperate assembly and loaded at runtime. After injected the user control it should then be loaded into the control collection of the page.
Everything seems to be working fine expect the point of adding the control to the page. There is no error but the UI for the control doesn't show.
global.asax.cs
protected override Ninject.IKernel CreateKernel()
{
var modules = new INinjectModule[] { new MyDefaultModule() };
var kernel = new StandardKernel(modules);
// Loads the module from an assembly in the Bin
kernel.Load("ExternalAssembly.dll");
return kernel;
}
and here is how the external module is defined in the other assembly:
public class ExternalModule : NinjectModule
{
public ExternalModule() { }
public override void Load()
{
Bind<IView>().To<controls_MyCustomUserControlView>();
}
}
The debugger shows that when the app is run, the Load on the external module is being called, and the dependency gets injected into the page.
public partial class admin_MainPage : PageBase
{
[Inject]
public IView Views { get; set; }
At this point when trying to add the view (here a user control) to the page, nothing is shown. Is this something to do with the way the user control is created by Ninject? The loaded control seems to have an empty control collection.
inside aspx page
var c = (UserControl)Views;
// this won't show anything. even the Control collection of the loaded control (c.Controls) is empty
var view = MultiView1.GetActiveView().Controls.Add(c);
// but this works fine
MultiView1.GetActiveView().Controls.Add(new Label() { Text = "Nice view you got here..." });
and finally the view/user control:
public partial class controls_MyCustomUserControlView : UserControl, IView
{
}
It contains just one label:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyCustomUserControlView.ascx.cs" Inherits="controls_MyCustomUserControlView" %>
<asp:Label Text="Wow, what a view!" runat="server" />
View 1 Replies
Jul 30, 2010
I wish to access a user control's public property from another user control. But, I am not able to access one user control within another. Even after using the namespace 'ASP', I am only able to see the reference to the current user control. However, in a page I am able to refer to all the user controls with the ASP namespace. Am I missing something or it needs to be that way?
Update:
Here the exact scenario - I have two user controls A and B. Now both of them are being used on a Page Default.aspx. There is a public proprty on control A which holds the name of the control clicked within A. I wish to access this property in control B to make some decisions. With the suggestions gioven by you, I understand reaching to the control by FindControl method of the container page, but how do I cast it to control A to fetch the property value when I cannot get the reference of the control A in B?
View 3 Replies
Jun 19, 2010
simply i take one user control and register it in one page now in this page i write a JavaScript function like this
function sethere()
{document.getElementById('<%=(test1.FindControl("TextBox1")).ClientID %>') = document.getElementById('<%=(test3.FindControl("TextBox1")).ClientID %>').value;
}
and now how to call it in user control,user control like this;
<ctrltest:test ID="test1" runat="server"/>
i tried this it not working;
<ctrltest:test ID="test1" runat="server" Onkeyup="sethere();"/>
i done only written above.
View 1 Replies
Apr 30, 2010
I have designed one user control, and used on my aspx pages whereever needed. My user control does not have tag. Now I want to call some javascript function onload of this user control. How to achieve?
View 1 Replies
Mar 21, 2011
I have a user control having a pagemethod. I want to call this pagemethod from my page using jquery's ajax() method?
View 5 Replies
Jul 22, 2010
I have a Masterpage and a UserControl inside the MasterPage itself.
I have a public method named PerformDragAndDrop inside the MasterPage and I want to call this method from the userControls's code behind.
View 9 Replies
Dec 9, 2010
I have a dropdownlist in a user control and i want to perform different functions on the basis of the host page that hosts this user control when the selected index of the dropdownlist changes e.g. when the host page is locations i want the event to load locations for the selected item in the dropdown, when the hosting page is services i want to load services for the selected item in the dropdown. What is the best possible way to achieve this scenario.
View 2 Replies
Nov 21, 2010
how to call a function of user control from the parent page?
I have a user control inside of default.aspx page, And I have a function in the code behind of user control. I need to call that function from a code behind of default.aspx
View 5 Replies
Feb 4, 2011
Can i bind and call the user control directly on click event of link button? instead of binding user control in another aspx page and then call it to the masterpage's link button click?
or else can i bind user control in a page lets say default.aspx and then call it in two different master page and show different functionality of it according to the masterpage its getting shown?
View 1 Replies
Mar 11, 2011
For an Umbraco project, I am trying to make a simple Ajax call.. I can't use PageMethods because I need to make the call from inside a UserControl.. I tried to do it via web service call like this:
Web service method:
[System.Web.Script.Services.ScriptService]
public class MapService : System.Web.Services.WebService
{
[WebMethod]
[Code]...
The problem is, "MapService.GetCities" method doesn't get invoked..
What might be the problem here?
Alternatively, what is there any better way to make these kind of Ajax calls in a User Control?
View 2 Replies
Jul 23, 2010
I have one user control which has 2 gridview first grid has columns (GroupName, Description, chkRemove checkbox) another gridview has columns (GroupName, Description, chkAdd), apart from that i dont have any code on .cs file of usercontrol.
I want to call same user control on 4 aspx pages and datagrid binding, sorting, paging and search functionality i want to do on respective aspx.cs pages not on user control where i am calling this uercontrol because for every aspx page field name is same but when i am binding the data to the grid that logic is different.
For first aspx page i called my usercontrol like this and everything is working fine: -
[Code]....
View 4 Replies
Apr 8, 2010
I have user control. Inside that have some buttons. my page has gridview . I want check grid view rows from user control button. User control is my menu. My grid has column with radio button.
When i click button of user control i want load item page which data which gridview radio button cheked true.
View 2 Replies
May 18, 2010
I have a grid with edit link.
when user clicks onedit link , i want to show modal popup extender which displays text boxes for editing those data.
when user finishes editing the grid should again updated.
View 2 Replies
May 12, 2010
I would like to use MVP pattern and add a presenter layer in my web app. EX;- for filling the data in page I am doing like this.
[Code]....
If I add a presenter class, Do I need to move this code in presenter layer?
View 2 Replies
Jul 14, 2010
I've exempted the irrelevant bits of code. Essentially, I am trying to change the URL of an image control inside of an update panel inside of a custom user control from a function called inside an update panel from my main page. Using UpdatePanel.Update() isn't working: I end up waiting for the next full page POST to occur before all the updates I make to CustomControl from buttons within the main page's update panel are visible. I verified that Update() was being called via the debugger: there are no issues in that department.
Here, you can see Custom Control and the Button declared. The button is in an update panel to avoid giving a full POST and causing the whole page to reload.
<cust:CustomControl runat="server" ID="CustomControl1">
<asp:UpdatePanel runat="server" ID="UpdatePanel1"> <ContentTemplate>
<asp:Button id="Button1" runat="server" OnClick="DoStuff" />
</ContentTemplate> </asp:UpdatePanel>
This control stores images within their own seperate update panels because rerendering the images is very slow (it requires processing arrays of millions of datapoints) and the user only ever needs to modify one image at a time. I'm using Image1 as an example.
[Code]....
View 3 Replies
Feb 16, 2011
This is not really a question so I hope don't be fired! So I have to make a twitter like timeline, a superposition of blocks containing informations.
I really don't know how to make this.. The problem is the number of blocks aren't the same each time, sometimes it will be 1 block only, sometimes two or sometimes more..
So do I make some HtmlWriter to write the html directly? I pretty new in asp.net so maybe it is possible to do that more easily! With WebUserControl maybe, a block = a wuc so I can add the number of wuc I need.. I'm quite lost so maybe somebody have done this kind of thing already and can put me on the right way..
View 1 Replies
Sep 20, 2010
I get the above error when trying to run my .net app as it attempts to connect to a SQL database on another server.
The SQL connection string is using a trusted connection.
IIS has anonymous access switched off, and integrated windows authentication switched on.
The user the error relates to is "DOMAINNAMEIISSERVERNAME$"
Do I need to add user "DOMAINNAMEIISSERVERNAME$" as a login on the SQL server machine?
I expected my username to be passed around - i.e. if I have access to the SQL server then the application would run fine?
EDIT: Should point out that I know it's authenticating OK from an IIS point of view... if I switch to anonymous access it fails my own security as an "Unknown User"... which is what I'm after
View 2 Replies
Jun 4, 2010
I don't think I understand fully how ASP.NET does inheritance of controls.I have a user control, ucBase, which has an asp.net label in the ascx file. Code behind references the label and it works fine during run time if the control is not a parent for another user parent.
If I have another user control, ucChild, inheriting from ucBase, the label in ucBase's code is always null. ucChild has no controls in its ascx fileThe server controls (like the label) needs to be declared in the ascx file and not created programmatically.What needs to be done for ucBase to see its own controls when it's a parent user control?
View 1 Replies
Jun 2, 2010
I have been reading about different model for development
model view control mvc
model view presenter MVP
Model view view model MVVM
i belive MVC has two big Advantage over webform 1) TDD 2) More control on HTML
MVP is bit variation in mvc model. rapid development as well as 1) TDD 2) More control on HTML (correct me if i m wrong) see the below link
[URL]
View 7 Replies
Apr 5, 2010
I have a ASP.NET Web Forms application and I'm using some dynamic controls in the view which depend on stuff that the presenter exposes. Is it okay for the view in this case to pull on the presenter for that data? Is there anything I should be extra careful about when considering testability and a loosely coupled design.
The page in this case has it's own page-life cycle and the presenter doesn't know about this. However, the page-life cycle dictates that somethings must occur at specific moments in the page-life cycle. This smells like trouble... Any known pit falls?
EDIT
When my concrete view hits the Init event it will pull on the presenter for a collection that will result in a bunch of ASP.NET server controls to be created. I'm wondering if this is a particular bad thing to do... The presenter doesn't know how to respond to the page-life cycle init event but it has to if the view is to be populated with dynamic controls.
View 2 Replies
Jun 11, 2010
What is the best way to get a number of property values of a business object from the View to the Presenter in a WebFormsMvp page?
Bearing in mind this issue with DataSources: [URL]
Here is what i propose:
The scenario is, I have a business object called Quote which i would like to load form the database, edit and then save. The Quote class has heaps of properties on it. The form is concerned with about 20 of these properties. I have existing methods to load/save a Quote object to/from the database. I now need to wire this all together.
So, in the View_Load handler on my presenter i intend to do something like this:
[code]....
View 1 Replies
Aug 16, 2010
I am using mvp pattern in small project. I have problems with view which contains html table with data(always 9 rows). How can i easily get data from html table and send it to the presenter? On the model side i want to keep data from html table as a generic List<some_type>
View 1 Replies
Jan 26, 2010
In Model-View-Presenter what is the correct pattern to do a page that:
a) contains a grid for browsing a list of items
b) an alternate mode for editing single items .maybe you are toggling between two asp:panels.
Do you just make the presenter smart enough to do two types of presentations?
Make 2 presenters?
I'm new to this pattern and want to do it correctly. I understand how I would do this functionality on two pages. Just not sure what is the accepted practice when the browse and detail exist on the same page.
View 1 Replies
Jan 27, 2010
I recently read Phil Haack's post where he gives an example of implementing Model View Presenter for ASP.NET. One of the code snippets shows how the code for the view class.
public partial class _Default : System.Web.UI.Page, IPostEditView
{
PostEditController controller;
public _Default()
{
this.controller = new PostEditController(this, new BlogDataService());
}
}
However, here the view constructs the instance of the BlogDataService and passes it along to the presenter. Ideally the view should not know about BlogDataService or any of the presenter's lower layer dependencies. But i also prefer to keep the BlogDataService as a constructor injected dependency of the presenter as it makes the dependencies of the presenter explicit.
This same question has been asked on stackoverflow here.
One of the answers suggests using a service locator to get the instance of the BlogDataService and passing it along to the presenter's constructor.This solution however does not solve the problem of the view knowing about the BlogDataService and needing to explicitly get a reference to it.
Is there a way to automatically construct the presenter object using an IoC or DI container tool such that the view does not have to deal with explicitly creating the BlogDataService object and also injecting the view and service instances into the presenter's constructor. I prefer to use the constructor injection pattern as far as possible.
Or is there a better design available to solve the problem?. Can there be a better way to implement this If i am building a WinForms application instead of a ASP.NET WebForms application?
View 2 Replies