I need to make an upload application. ASP.NET already has an UploadFile control. But there is one more requirement: to be able to select a folder and to upload all his content. So I need to create an FolderBrowse control to be able to select a folder. Becase the SelectFile dialog that is included in UploadFile control looks so professional the DirectoryBrowse should look the same. I google it and found 2 solution: 1. to create in windows form a control that opena a file and opens a folder and gives the consumer the selected path.... and 2. it was something with using interop to be able to use a .net folderBrowse control ....not very clear to me this one that's why I tried to create an windows forms control and embed it in web site. The problem is:
1.
In designer I got an text over the control : The control type was not specified or the specified type could not be found.
in browser I see a little rectangle where the control should be.
If I add type = application then in browser I see nothing at all.
In win forms control I set for the user control:
[ComVisible(true)]
Can someone give me a clue please? what I am doing wrong? Or maybe another solution?
Related
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.
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
I have a database where i have the physical path where image of a person is stored .
now i want a code by which I can display the image of that person in a aspx window.
as I am new to asp.net & C#
can somebody provide me the full code of aspx page and the C# code behind it?
Here's a good example on how to connect to a database and display the data in ASP.NET: How to: Bind to Data in a Templated Control on MSDN.
Also there a lots of great tutorials on the ASP.NET "official" site.
Update:
Alright, now we got something to work with. Do you know if your HttpHandler is throwing any exceptions? Place a breakpoint in the HttpHandler code and hit F5 (Visual Studio) to launch the site in debug bug mode. Maybe you're not passing an image ID to the handler? Try and hardcode an ID in the .aspx for an image you know that exists in the database.
See if you can update your question and format the code: Just select the code sample and click the "code" button in the editor. It will indent the text and apply nice formatting, making it easier to read.
Also include your .aspx page so we can see what's going on there.
So I'm having problems when I try to publish the website.
I'm in visual studio 2008 sp1.
I've got a bunch of user controls and on a few pages I'm using them programatically.
I've got a reference on the aspx page
<%# Reference Control="~/UserControls/Foo.ascx" %>
Then on the code behing I use
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
If I navigate to the page it works fine, but when I goto publish the website I get a compile time error.
Argh, I'm bleeding development hours on this same issue. Does anyone have a solution to this ?
BTW: It builds if you uncheck "Allow this precompiled site to be updatable" (Right-click on the website, choose Property Pages, MSBuild Option)
But I need the site to be updatable.
I had this same problem - actually, in my case I could get it to compile and build my website, but it would blow up spectacularly when doing an automated build.
Try replacing your code as follows:
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
with
USERCONTROLS_Foo newFoo control = (USERCONTROLS_Foo)Page.LoadControl("~/UserControls/Foo.ascx");
(Capitalization will be based on how you capitalized your directory name/control name - but in either case should highlight appropriately).
Specify a namespace for user control (see Dynamically Load a user control (ascx) in a asp.net website ).
I've found a solution for it. If i'll declare controls in user defined namespace, then I can use controls directly without using ASP or referencing it into aspx page.
It may have something to do with the specific type not being available. Can you change the control reference so the type and cast just use the base Control class:
Control control = Page.LoadControl("~/UserControls/Foo.ascx");
Yes, I can cast it to Control. But then I lose direct access to the methods on the usercontrol.
I know that I can access the methods by reflecting into the control, and I've successfully done that but that's far from ideal to access all the other user controls on the site.
Also, the follow-up error is that it cant find the usercontrols that on the markup
<%# Register src="CategoryRows.ascx" tagname="CategoryRows" tagprefix="abc" %>
<abc:CategoryRows ID="CategoryRows" runat="server" />
Note that I can run the site successfully both locally and on the server if I essentially XCopy the entire site (source code and all). But Publish fails.
Casting the user control may create many problem .my approach is to create a class (say control Class) put all the properties and method you need after casting and inherit this class from System.Web.UI.UserControl .Then in your user cotrol code file instead of System.Web.UI.UserControl user this control class .
now when ever you need casting cast with this class only . it will be light casting as well.
Please check:
Do you have any website.publishproj file?
If it exists, then delete and try again and publish code.
I have a series of .NET 2.0 web pojects that have identicle code behind in their web pages. The only thing that is different is how the html is laid out.
Is there a way that I can have a main web project that holds all the code behind (including control events like button click) and so that the other web projects reference the web page code file to this project's code files?
Edit: Note that the changes in html include exclution of certain controls, I am catoring for this by using the FindControl method so that if the control doesnt exists, I would simply have a null value.
You may try putting all the code-behind classes into a library and inheriting from a common base-class.
You can take a look at "Skin File" file type of Visual Studio. On the other hand you can learn if it works for you from the address below: http://msdn.microsoft.com/en-us/library/ykzx33wh(VS.80).aspx