Is it possible to create a .xaml (silverlight) control in a web application project?
I have an aspx application wherein I am using ajax controls and updatepanel. I want to create some silverlight controls in the same project, and load it along with my other pages/controls.
I am not sure if it is possible to create a silverlight control without having a dedicated silverlight project template.
I think your question is the same as one of mine: Is there a way to insert Silverlight XAML into my page using ASP.NET code-behind?
If so, the answer is basically "not in any sane way, but you can hack it by setting up different parameters (as in weiqure's answer) and using them to dynamically generate the XAML."
I'm not sure if this answers your question, but you can have a solution file that contains your web app and a Silverlight control. Then, to include the control in your web app, add it via the "Silverlight Applications" tab in the web app's project configuration. This will auto-update the .xap file in the web app's ClientBin folder.
Alternatively, you can create the Silverlight control in its own project/solution outside of the web app solution. Then you just need to copy in the .xap file to the web app's ClientBin and add it to your aspx page the usual way. I've found this approach useful when I want to deploy the same control to multiple web sites/projects.
Instead of creating several controls you might try creating one control that dynamically creates it's own content.
You can tell the control what to do by passing initialization parameters to it. Here's the MSDN tutorial and here's a blog post about it.
I think this approach is no worse than creating controls dynamically. You can probably send it XAML markup (I'm not sure if I remember that correctly, though), otherwise you could path something like "myButton=Type:System.Windows.Controls.Button;Content=Click me!" and then use reflection.
Related
There is probably a very simple solution to this problem but since I do not know Sharepoint at all and cannot seem to google my way to wisdom on this one maybe one of you guys can steer me in the right direction.
Background:
Currently I am working in a project where a part of our web solution is constituted by Sharepoint and I have absolutely no previous experience from Sharepoint. Lately I have been struggling with what looks like a very simple task, adding a (web) user control to one of the Sharepoint pages in our solution. There are two important requirements on this task;
The user control and the code-behind must lie in and make up a separate assembly
That assembly must be signed
The user control assembly is really another ASP.NET Web application with a Default.aspx so I may debug the user control with mockups using Cassini. When I debug it through Default.aspx it works fine, the user control is displayed and I can use it as intended.
I have these lines in my web.config:
<SafeControls>
[..]
<SafeControl Assembly="MyMainNamespace.SubNamespace.SelectorPopup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7fa78676161515a2" Namespace="MyMainNamespace.SubNamespace.SelectorPopup" TypeName=" *" Safe=" True " />
[..]
</SafeControl>
And on the Sharepoint page I have put the following:
<% #Register TagPrefix= "Selector" Namespace="MyMainNamespace.SubNamespace.SelectorPopup" Assembly="MyMainNamespace.SubNamespace.SelectorPopup" %>
[..]
<Selector:SelectorBoxControl runat="server" SelectorType="ContentArea" ></ Selector: SelectorBoxControl>
Our project is an ASP.NET web project on .NET 3.5 (2.0) deployed on IIS6 (Windows Server 2003) and we are using Sharepoint 2007, SQL Server 2005. Build, deploy and Visual Studio markup is fine.
Problem:
After deploy to our test environment the user control is not displayed at all on the Sharepoint page and I canĀ“t figure out why.
Build and deploy works fine and the Sharepoint page is even displayed, just that my control is nowhere to be seen. Actually, the HTML response contains absolutely no trace of my user control. Even if I put pure HTML text and no functionality in the control. There are no error messages and the event handler provides no information about possible errors or warnings.
Am I missing something? Is there anything I need to enable, an attribute I need to add or a reference somewhere? Is there anyway I can get this non-display behavior generate an understandable error message?
I think you need to register your dll with the GAC for SharePoint to find it. I could be wrong there though and copying to the bin dir does the trick.
But I'm quite sure you need to user the fully qualified name in the Assembly attribute when registering.
<% #Register TagPrefix= "Selector" Namespace="MyMainNamespace.SubNamespace.SelectorPopup" Assembly="MyMainNamespace.SubNamespace.SelectorPopup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7fa78676161515a2" %>
I'm posting this as an answer because, despite our exchange in comments, I'm not sure you and I have been talking about the same thing.
As you know, there are two kinds of controls in ASP.NET, user controls and web custom controls. User controls have an .ascx file containing markup and - this is important - can't be shared between projects. It does no good to compile the project they're in and reference that assembly, because the .ascx file is not part of the assembly. Web custom controls don't have a markup file: they are entirely created in code, with their controls being created programmatically and added to the Controls collection of the custom control.
So either the third party control in its separate assembly that you're replacing is a web custom control, or - if it uses a separate markup file in its source - it must be using a trick, such as the Virtual Path Provider trick, to achieve this.
You've talked about your user control and your code-behind as if they were separate things, which has led me to believe that you are indeed talking about a web user control. But these simply can't be shared between web projects. If your control needs to live in an external assembly, the simplest thing to do is re-write it as a custom control that builds its contents programmatically.
There are other options, such as the Virtual Path Provider solution, or a famous one from Scott Guthrie (here). But the least tricky option is to write it as a custom control.
I recently tried to create an ASP.Net server control. This server control should has at least two pages. One page for registration (Users can register) and one for asking questions. It is important to make it with ASP.Net Server Control.
The plan is to make this server control and web designers can easily drag and drop this server control into ASP.Net WebForms or MVCs and set properties like back-color or header image in properties tab. I wonder if its possible to have two pages in a server control dll file with all events, viewstates and properties.
Please some one tell me how to create a second page in a server control dll file? And another question is how to move between those pages?
As per my understanding you should go for MultiView or ASP:Wizard control ?
Maybe you are looking something like this from codeproject.
I would like to subclass an ASP.NET control, like UpdatePanel, and use the subclass in my web site. I know if I move the code to a separate assembly I would be able to reference the assembly from within Register phrase but I wonder if there is a way to keep all the code inside the website.
Would appreciate to have your help.
Sure, you can put code files in App_Code if you are using the web site project template, or if you are using the web application project template, the code can be within a folder in the web site.
Note that the name of the assembly in web site project templates is App_Code, and for web app projects its the name defined as the assembly name in the project settings.
Do you know which template you are using?
When it comes to custom controls, sometimes you may run into issues, especially if you want to change the existing behavior of updatepanel.
HTH.
I am new to share point. i would like to add custom .aspx pages in share point. this i was able to do it using this blog http://chiragrdarji.wordpress.com/2007/10/12/add-aspx-page-to-sharepoint-2007/#comment-3540 .. now i would to inherit the share point's master page in my asp.net application and implement some controls. can any one help me out regarding this?
thanks and regards
malathy.L.
Using the sharepoint master page in another app is not going to work. It has a bunch of sharepoint specific controls on it that your custom app won't recognize. It is much easier to put all your app's logic (i.e. all controls now in an ASPX page) in a USerControl and use those on ASPX pages in SharePoint.
Then to be able to use these controls you need to do either of these options:
Then deploy either by putting the .ascx files in the CONTROLTEMPLATES folder in SHarePoint's 12 hive and the DLL in the bin folder / Global Assembly cache. If you go for the BIN folder you would probably need to write CAS Policy files though. This is the most secure method.
use the SmartPart.
I'm guessing you are very new to SharePoint , but want to urge you to consider packaging all this up in a SharePoint Solution (a .wsp file) using a tool like WSPBuilder.
Also I would encourage you to read up on SharePoint Development / Deployment Best Practices check out this Checklist.
How to add or open the asp.net pages from inside sharepoint?
I found many info on the web about that, but they all fail or they are not clear. I appreciate your help :)
Your question is not clear, but if you want to customize look'n'feel of SharePoint page you should use SharePoint Designer.
In case you want to create some additional functionality from scratch the easiest way is to create a custom web part and then add it to a SharePoint page.
I think you want to include an aspx page to call either using an AJAX include or to be able to use the MOSS Object Model without having to add references etc?
if so then the following steps are necessary:
navigate to 12\layouts\
create a folder for the asp.net files
put the inline code files in
From sharepoint you can add a page viewer web part and reference it with the following url _Layouts//Filename.aspx
This technique will only work with inline code, if you wish to compile your code then you would create the site as normal and then add an application folder within the virtual directory of that particular site for example my site is called intranet:
navigate to c:\inetpub\wwwroot\wss\intranet
add your asp.net folder to this as a sub folder
in inetmgr right click the folder and create an application for it (use the same app pool as the sharepoint site)
ensure ALL DLLs from the sharepoint site bin folder exist within the apps bin folder or it will throw an error.
However, I would only ever use these methods as proof of concept and would ultimately use web parts, custom features and workflows to carry out the same functions.