I have been given the task to create a "Web Part" for a Sharepoint website. The reason i quote "Web Part" is because i don't think that it suits my needs.
With a User Control a developer is absolutely free in what kind of control he wants to add. This can easily be done in the (for example) MyUserControl.aspx file from the MyUserControl.ascx control. You can even add jQueryUI elements to the User Control like tabs etc.
So basically i need to be free in what kind of (HTML) elements i add to the page and what not.
Since it looks like this can't be achieved with a SharePoint Web Part i want to know if it is possible to display a User Control instead?
Is there a way to do this..??
If you use Visual Studio you can select "Create new Visual WebPart", provided it is SharePoint 2010 we are talking about?
This option gives you a ascx-file which you can treat like a normal usercontrol. It is automatically wrapped as a SharePoint-webpart.
See this walkthrough for more thorough information:
http://blogs.msdn.com/b/bethmassi/archive/2010/01/28/creating-a-sharepoint-visual-web-part-using-visual-studio-2010.aspx
You cannot add User control directly to a specific SharePoint page, but you can add to Master Page or Page Layout. (And only by SharePoint designer)
Another option is to create User Control add load it to Web Part, and add the Web Part to your page.
Edit:
As Rikard Uppström wrote, in VS2010 there is template named Visual Web Part that does exactly that for you, but if you work in SP 2007 you can do it yourself.
Related
I have just begun using ASP.net heavily.
In Visual Studio when I open a web form with a master page in design view, it is not really very comfortable to work with.
Is there any way to hide master page so that I can concentrate on my form ?
If not, can I use a user control as a web form and embed it into the actual form as a work around ? (I know it does not exist for this purpose)
Just remove MasterPageFile="~/MasterPage.Master" from the page header. when your design is complete add it again.
I guess this is a lot of questions bundled into one post.
I want to build a wizard-like control which looks similar to the TabContainer
But I need certain customizations. These would be like I'd want to associate some help text with the TabPanel. So I imagine I'd want to write my markup like below for the tabpanel:
<cc1:MyTabPanel ID="mtp1" runat="server">
<HelpTextTemplate>
This is your step 1 which is about ...
</HelpTextTemplate>
<ContentTemplate>
Content goes here...
</ContentTemplate>
</cc1:MyTabPanel>
So what do you do to make markup like that...? And how would our control from code behind be able to access data between HelpTextTemplate - which may contain server controls and all?
Moreover, notice that there is a button called 'Save' in the above pic. The user simply drags and drops into the tab panel. And when the user double-clicks on it we have a method stub generated in the code behind (which belongs to the aspx page). How is all of this achieved?
And to cap the whole solution off, I realize we have to wire some javascript to simulate that tab functionality. There is css here too (Notice the images behind the tabs - the gradient, etc). The aspect that I am looking at is making this into a control that the users can use out-of-box just like the toolkit's tabcontainer control. Hence the css/javascript should kind of be bundled. How to achieve this?
Edit:
I am also interested in making the control designer (design-time interaction) part. I am looking for functionality the same way we have for the asp.net wizard control. I have found answers to some of the questions I had above will add it when I find time.
For embedding a script or image to the asp.net custom control I found a solution mentioned in the below site:
Embed js resource with custom asp.net control
What I suggest here it may sound too much, but I can not think other easy way for what you ask and the way you won it.
Grab the source code of the TabContainer, clone it, and make all your custom settings base on that source code. The first steps is to get the full source code of this asp.net toolkit and make a build that working. The second step is to add a clone of the TabControl, with new names. Then you work on this clone to make your changes as you wish for. The final step is to try to separate your custom control in a stand alone library if this is possible.
Download the latest version of the full asp.net ajax control toolkit
http://ajaxcontroltoolkit.codeplex.com/SourceControl/list/changesets
Here you can see online the source code for the TabContainer only
http://ajaxcontroltoolkit.codeplex.com/SourceControl/changeset/view/2c482e5ad6c4#Server%2fAjaxControlToolkit%2fTabs%2fTabContainer.cs
The control you are trying to build is not incredibly complex, but it does involve a number of different techniques.
I would suggest creating your own control from scratch rather then inheritting an existing one. Probably using CompositeControl as the base would be best since it gives you a lot of flexibility.
For HelpTextTemplate/ContentTemplate you'll want to create some ITemplate containers, take a look at this article http://msdn.microsoft.com/en-us/library/aa478964.aspx on how to set these up. Since you may want to access the contents/controls in HelpTextTemplate take a look at this article for how to access them: ASP.Net ITemplate - ways of declaring.
For the tabs, since this is custom, I would probably avoid AjaxControlToolkit. Instead I would include a reference to jQuery UI and use jQuery UI Tabs: http://jqueryui.com/demos/tabs/. Your CompositeControl just needs to output some divs, ul/li elements and you'll be good to go for making the tabs.
If you are fixated on using the AJAX Control Toolkit Tabs then you still can. You'll need to instantiate an instance in your custom control, add it to the control tree, and then use a technique like this: http://msdn.microsoft.com/en-us/library/0e39s2ck.aspx to transfer the contents of your template to the tab pages.
Being able to drag and drop a control from the toolbox onto your page is simple; if your server control library is already part of the same solution as your website then it will just show up. Worst case scenario you can use the Add Items option and add the DLL by browsing for it. As for how the Click event is created when you double click a button, that is done through an attribute on the class, take a look at this tutorial on setting up default events: http://msdn.microsoft.com/en-us/library/43sxkdeb.
As for embedding javascript into the library, these two questions cover how to do this specifically for jQuery UI, if you choose to go some other route it should still be pertinent: How to embed jquery library in asp.net custom server control?, http://forums.asp.net/t/1599621.aspx/1.
As for design time support, try reviwing Microsofts article on this (includes a sample): http://msdn.microsoft.com/en-us/library/aa478960.aspx or this CodeProject article on it: http://www.codeproject.com/Articles/9227/ASP-NET-Server-Control-Design-Time-Support.
in Visual Studio 2010 I have a really big ASP.NET website project which has a bunch of user controls.
How do I determine all the .aspx pages where a specific .ascx user control is referenced throughout the project.
Thanks
Right click the class of your User Control and Select the below option.
Find All Reference
The simplest way I can think of is to just use the Find In Files (Ctrl/Shift-F) search dialog.
Find what: name of user control
Look in: Entire project
Using visual studio 2008. When I add a new aspx form to a project I am not offered the option to choose a master page even though there is one in the project. How do I turn that option on? It appeared automatically in the past.
When you add a new item make sure you select Web Content Form and not Web Form. Then you'll be able to select the MasterPage.
I've always wondered what is the best way to add a new item to html-select in a website.
Yes, this may sound silly but it is a great problem from the usability perspective. I don't want the user to be taken to a new page every time they need to add new item to a html-select.
I like the way Google Reader and Gmail handle this problem in there "add folder" and "add label" functionality. I would like to mimic that but i have no clue how they did that.
I'm using jQuery, so any reference to plugins, code examples or tutorials are welcome.
I would like it to be as modular as possible so i can reuse it anywhere.
I'm using ASP.NET 3.5 web-forms, Microsoft Access 2003, jQuery, IIS 5 and Win XP Professional as web server.
Thanks.
there's a jquery select plugin that might help you with this. I've manipulated select lists client side and had no problem with subsequent form-submits but you'd need to do some experiments w asp.net
The standard technique of doing this is called ajax, which basically means replacing only parts of the page. JQuery ajax and maybe a tutorial should get you going.
A common mistake for this scenario is to add the item on client (using jQuery or plain javascript). It may look that it works until the next post-back. Unfortunately the Asp.NET post-back model does not allow to alter the controls contents on client side only. So basicaly there are two choices:
Use ajax (the simplest would be to
use an UpdatePanel)
Make a normal
postback to add the item (simple and
fast to code, if performance is not
an issue - for intranet applications
for example)