Injecting A Web User Control With Ninject In WebForms

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


Similar Messages:

MVC :: Use Html Helpers/Repositary Pattern/Ninject In Webforms?

Nov 25, 2010

Just Wondering. Can we use Html Helpers/Repositary Pattern/Ninject in Webforms?

View 1 Replies

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

C# - How To Display A List Of User Controls In WebForms

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

C# - Sys.WebForms.PageRequestManagerServerErrorException: Login Failed For User?

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

Server Controls In User Control Are Null When User Control Serves As A Base User Control ?

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

Use Ninject 2 In MVC 3 Application?

Jun 10, 2010

Ive searched everywhere, i can't seem to find a way to implement ninject in my project. Ive heard of deriving MvcApplication to the NinjectHttpApplication. But NinjectHttpApplication isnt found even if i add the lib to the reference. I can't find Ninject.Web.Mvc. Does anyone have a guide somewhere in order to make this work, all i want to do is be able to bind my interface from my domain to existing implementation.

View 4 Replies

Options For Wiring Dependencies With NInject?

Jan 27, 2010

With NInject (preferably 2.0), what options do we have wrt wiring up our object dependencies in a web application?

Can they be defined in an XML configuration file?

Or does it have to be done via code?

View 4 Replies

Using Ninject With WCF Services Within Web Applications Appdomain?

Feb 4, 2011

It's my understanding that if you want to use the WCF-Ninject extension, it assumes that you are hosting your WCF services in their own AppDomain.

I'm already using the Ninject.Web extension and asp.net compatibility mode to get at the Membership Provider and Session.

Is there a way utilize my Ninject with my WCF services that are hosted in the same AppDomain as my Web Application?

View 1 Replies

.net - Trouble Defining Bindings Using Ninject?

Mar 28, 2011

having trouble defining bindings using ninject.I am in a standard ASP.NET WebForms application. I have defined an http handler to Inject dependencies in pages and controls (Property injection).Here is what I am trying to do:I am creating a custom combobox usercontrol. Based on the value of an enum on that combobox, I want to be able to Inject a different object in a property (What I am trying to do is a bit more involved than that, but answer to this should be enough to get me going).

View 1 Replies

Add New Object To Track In Ninject After Application_Started?

Sep 5, 2010

Is it possible to add a new object that Ninject should be responsible for (lifetime, injection etc.) in an ASP.NET application after the Application_Started event is fired?

My application needs to dynamically designate objects that should be tracked well after the application is started

View 2 Replies

NInject Work In Medium Trust Hosting?

Apr 11, 2010

I'm doing shared hosting with GoDaddy and I developed a sample ASP.NET MVC app using Castle Windsor and unfortunately, it didn't work in a medium trust setting. Specifically, I got this error: "[SecurityException: That assembly does not allow partially trusted callers"... etc. GoDaddy is sadly not flexible in their trust policy.

I'm not tied to Windsor and would like to try another one that will work under Medium Trust. I'd actually like to use NInject, but I've read people having mixed success. The only one I've read that works with no problem is Microsoft's Unity.My question is, does NInject work in medium trust? If not, what are my options?

View 2 Replies

Cannot View Controls In Design Mode Using Ninject.Web

Mar 4, 2011

I'm playing around with dependency injection in a web-forms website al a Ninject and whilst I have had no problem at all getting the site running smoothly I've had a pretty big problem when viewing individual pages using design mode.

I wouldn't normally use design mode but dragging and dropping web user controls onto a design space is the easiest way by far to add them to a page.

The set-up is pretty much identical to guidelines here The error on the design page is thus:

The type "page name" requests an injection, but no kernel has been registered for the web application. ensure that your project defines a NinjectHttpApplication.

I'm using Asp.Net 4.0 with Ninject and Ninject.Web 2.2 utilizing property injection

View 1 Replies

Asp.net - To Prevent A Single User Account Logging On Multiple Times In A Webforms Application

Dec 16, 2010

I am looking at how best to prevent a single user account logging on multiple times in a webforms application. I know that MembershipUser.IsOnline exists, but I've read a few forum and blog entries suggesting that this can be unreliable, particularly in scenarios where a user closes a browser (without logging out) and attempts to logon with a different machine or browser.I looked at implementing a last past the post type system; when a user logs on older users are simply kicked off. It seems that FormsAuthentication.Signout() only works for the current user.

View 2 Replies

MVC / Ninject - Single Instance Per Request For Multiple Constructors?

Oct 9, 2010

Im trying to implement an unit of work pattern by passing an unit of work instance into my repositories.

Relevant code from Global.asax.

[code]....

What i want is that a maximum of 1 instance of SqlUnitOfWork is created per request and is passed into my repositories (via their respective constructors).

Is the InRequestScope() method on the IUnitOfWork binding enough? If not how can i achieve this?

View 1 Replies

MVC 3 Application Using Ninject, Entity Framework 4 Code-First CTP 5, Patterns

Jan 24, 2011

ive tried to build some base project with above technologies. I wanted maximum flexibility and testability so i tried to use patterns along the way to make this as a base for future projects. However, it seem.something is wrong or whatever and i really need help here. So

i have two questions :1- Is there anything wrong with my current code ? Ive applied patterns correctly ?

2- Why do this code actually connect to the database, create it, but doesnt support insert even if i perform the corrects operation ? (Look at the end of the post for details about this error)

I have two entities : Comment and Review

COMMENT [Code]....

REVIEW[Code].... I built up a base repository for each of them this way :GENERIC REPOSITORY[Code]...For specific operations, i use an interface :[Code]....So i am getting the generics operations from the abstract class plus the specific operations :[Code]....As you figured out, i also use a database factory will produce the database context :DATABASE FACTORY [Code]....DISPOSABLE (Some extensions methods...)[Code]....DATABASE [Code]....And to finish, i have my unit of work....UNIT OF WORK[Code]....I also binded using Ninject the interfaces :NINJECT CONTROLLER FACTORY [Code]....however, when i call in the constructor ...[Code]....

This seem to create the database but doesnt't insert anything in the database in EF4. It seem that i may figured out the problem.. while looking at the database object.. the connection state is closed and server version throw an exception of this kind :

ServerVersion = '(((System.Data.Entity.DbContext (_database)).Database.Connection).ServerVersion' threw an exception of type 'System.InvalidOperationException'

I am doing the right things ? Is there anything wrong in what ive built ? Also if you have recommandation about the code i posted, i would be glad. I am just trying to the learn the right way for building any kind of application in MVC 3. I want a good a start.

I use :
- Entity Framework 4 Code-First CTP 5
- ASP.NET MVC 3
- Ninject as DI Container

View 4 Replies

Dependency Injection - Use Rhino Service Bus On Website With Ninject?

Aug 6, 2010

I will like to add Rhino Service Bus to my ASP.NET web application but using Ninject as the DI Container. So far all examples I keep seeing use Castle Windsor which I don't want to use since we already use Ninject.Are there any tutorials out there which show how to add Rhino Service Bus to an ASP.NET web application without a direct dependency on Castle Windsor (e.g. using Ninject)?

View 1 Replies

Injecting Today's Date In Javascript?

Feb 15, 2011

When the page loads, I want a variable inside my JavaScript to hold today's date. So far I have this:

<script type="text/javascript">
var TodayDate = <%Eval('System.DateTime.Now') %>;
</script>

It massively bugs.

View 5 Replies

Dependencies Not Injecting - No Method Working

Jan 11, 2010

I am trying to create an ASP.NET MVC application, using Spring.NET to inject dependencies. The application has three tiers: Controller, Service, and Data. I have defined the objects in the file "~Resourcesobjects.xml". My first object, UserAccountController, requires the injection of two Service-tier classes: UserAccountService and DepartmentService. So, the definition in objects.xml looks like this:

<object id="UserAccountController" type="App.Controllers.UserAccountController, App">
<constructor-arg index="0" ref="DepartmentService" />
<constructor-arg index="1" ref="UserAccountService" /> </object>
<object id="UserAccountService" type="App.Service.UserAccountService, App">
<property name="UserAccountDao" ref="UserAccountDao" /> </object>
<object id="UserAccountDao" type="App.Data.UserAccountDao, App" />
<object id="DepartmentService" type="App.Service.DepartmentService, App">
<property name="DepartmentDao" ref="DepartmentDao" /> </object>
<object id="DepartmentDao" type="App.Data.DepartmentDao" />

Webconfig contains this:
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
</sectionGroup> </configSections> <spring> <context>
<resource uri="~/Resources/objects.xml" /> </context> </spring>

I would prefer to use Property injection rather than constructor, but currently neither method is working.

View 3 Replies

Injecting JavaScript Outside An Update Panel?

Jan 8, 2010

I have an aspx page with four UpdatePanels. Incidentally, each UpdatePanel corresponds to a JQuery UI tab. What I am trying to achieve is a JQuery UI modal dialog OUTSIDE the UpdatePanels that can be called from server-side code running INSIDE any of the UpdatePanels. So, inside the first UpdatePanel is an asp:Button which runs some server-side code. When an error ocurrs, I want to be able to inject some JavaScript that will call the modal dialog to display the error message. Here is the code I am using:

Dim script As String = "showPopupMessage('{0}');"
script = String.Format(script, errorMessage)
ScriptManager.RegisterStartupScript(Me.UpdatePanelBizInfo, Me.UpdatePanelBizInfo.GetType, Guid.NewGuid.ToString, script, True)

The showPopupMessage function on the page looks like this:

function showPopupMessage(msg) {
$('#<%=Me.LabelPopupMessage.ClientID %>').text(msg);
$('#dialogPopupMessage').dialog('open');
}

When the code runs to inject the JavaScript, nothing happens. I am assuming it has something to do with the fact that the error ocurrs in the code running inside an UpdatePanel. Upon inspecting the resulting HTML, the JavaScript is there. What am I doing wrong?

View 1 Replies

MVC :: Injecting The Session Into A Wrapper Class

Aug 13, 2010

I've seen how to Fake the SessionState object in MVC using Scott Hanselmans MvcMockHelpers, but I'm dealing with a separate problem.What I like to do is create a wrapper around the Session object to make objects a little more accessible and strongly typed rather than using keys all over. Here is basically what it does:

public class SessionVars{ public SessionVars() {} public string CheckoutEmail { get { return Session[checkoutEmailKey] as string; } set { Session[checkoutEmailKey] = value; } }}

So that I can just do this in my controllers and views:

SessionVars s = new SessionVars();s.CheckoutEmail = "test@tester.com";

Now the problem comes in when I want to write unit tests, this class is tightly coupled with the HttpSessionState. What I can't figure out is what is the right class to accept/pass so that I can pass in a FakeHttpSession into the SessionVars class. I've tried so many things with this, and this (below) will compile, but it can't cast the HttpSessionState into the IDictionary. I've tried ICollection, HttpSessionStateBase.

public class SessionVars{ public SessionVars() : this(HttpContext.Current.Session) { } public SessionVars(ICollection session) { Session = (IDictionary<string, object>)session; } public IDictionary<string, object> Session { get; [code]...

I'm missing something big here. I feel like this is possible and that I should even be that far off.Furthermore, I'm confused as to whether I should use the IHttpSessionState, HttpSessionStateBase or the HttpSessionStateWrapper. What is the abstract type that I'd use for the session object inside my SessionVars class? What is the type that I pass into the constructor?

View 3 Replies

Injecting Table Row Inside Repeater Item

Apr 8, 2010

I am trying to inject inside repeaters items, the problem is that the row is generated in a wrong location. If you try this simple example, you will see that the rown is generated under label '2' as it should be generated under label '1'. Why does it happen? And how to fix that?

protected void Page_Load(object sender, EventArgs e)
{
int [] array = {1,2,3,4,5};
rpt.DataSource = array;
rpt.DataBind();
}
protected string _extraRowHtml;
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
int tmp = ((int)e.Item.DataItem);
_extraRowHtml = tmp == 1 ? "<tr><td class="topicsRow" colspan="100%"> Topics </td></tr>" : string.Empty; ;
}
}
<asp:Repeater ID="rpt" runat="server" onitemdatabound="rpt_ItemDataBound">
<HeaderTemplate>
<table cellpadding="0px" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>
<tr style="height:50px">
<td>
<asp:HyperLink ID="lnkTitle" runat="server" Text='<%# Container.DataItem%>'/>
</td>
</tr>
<%# _extraRowHtml %>
</ItemTemplate>
<FooterTempl
</table>
</FooterTemplate>
</asp:Repeater>

View 2 Replies

Chained Base Class Properties Not Injecting

Apr 2, 2010

I am successfully injecting base class properties with spring.net with just a class that inherits from a base abstract class. Lets say Class MyClass : MyBase, and I am successfully setting a property like this:

<object id="myInstantiableClass" type="myAssembly.MyClass myAssenbly" abstract="true">
<property name="MyBaseClassProperty" ref="anotherObjRef"></property> </object>

Where MyBaseClassProperty is a property on the base class. Now I have another abstract class between the old base class and the instantiable class and I am trying to set properties on both the abstract classes. So MyClass : MyNewBaseClass and MyNewBaseClass : MyBaseClass. I have an additional property on the new base class (MyNewBaseClassProperty) and I am trying to inject it like this:

<object id="myInstantiableClass" type="myAssembly.MyClass myAssenbly" abstract="true">
<property name="MyBaseClassProperty" ref="anotherObjRef"></property>
<property name="MyNewBaseClassProperty" ref="someOtherObjRef"></property>
</object>

The property on the old base class is being injected but the one on the new one is not - and I am not getting an error or anything (so I am pretty sure my config is good), that property is just null! I am on asp.net (not MVC) and the class MyClass is a user control (ascx).

View 1 Replies

AJAX :: Injecting Javascript Via Append Into PopupControlExtender?

Jan 18, 2011

I have a page with a grid view that the user can hover over an image within the row and it will retrieve additional information from the database and show it in a panel called by the PopupControlExtender.

I then wanted to add a bing map showing the location within the same panel. This also works correctly EXCEPT I can't seem to get the map to show automatically. If I add a Mouseover or click event it works, but no matter what I try (inline, function, etc.) I can't get it to show when the panel shows. The user has to take action for it to appear which is not what I want.

Here is the section of code with the bolded section the code that is problematic:

Again - I just want the Mouseover requirement removed so that the map will show without further input

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
string[] strArrayVal;
string CK;

[Code]....

View 1 Replies

C# - How To Pass A Value From MVC Controller To Webforms Control Inside MVC View

Dec 24, 2010

My way to ASP.NET MVC was not across ASP.NET Web Forms, so it's hard for me to understand how better to pass value from ASP.NET MVC controller to ASP.NET webforms script which is inside MVC View.

For example, controller action:

[Code]....

How to assign a value of myvar from a controller action to par1 variable in the View instead "stubvalue"?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved