Webusercontrol objects not working - c#

I am using some web user controls on a website I am creating, but the problem is that sometimes visual studio cant load the control because he (my guess) needs a namespace imported where the web user control is located in. To make things more clear here's the line of code I am reusing to make objects of the web user control.
Criterialijn criterialijn = (Criterialijn)LoadControl("~/Criterialijn.ascx");
When I first execute this, he does not know about what object I am talking about, but when I drag and drop the .ascx control into the app_code folder and drag and drop it back out, everything is fine : he lets me load the web user controls and knows about what object I am talking about. Now this is a kind of retarded solution so my question is how do I fix the web user control so that he immediately knows about what object I am talking about when I create it?

This is how I do using a placeholder. Hope it helps.
Criterialijn criterialijn = (Criterialijn)LoadControl("~/Criterialijn.ascx");
PlaceHolder1.Controls.Add(criterialijn);

Related

Linking Image control and FileUpload control

As the heading suggests, I'm trying to give the user the option to choose an image using the FileUpload control and after hitting the update button, display it in the Image control, existing inside a Panel control.
So far I've gotten here. This is my form.
And this is my code.
I let the highlighted code stay inside PageLoad function just for testing. I know it should be inside the Button's event handler.
Also, can someone explain me why the above fails to display the image even after hardcoding an absolute URL for Image.ImageUrl property. It worked when I referenced it just by giving the file name cake.png and putting the file inside the website folder. But I want to reference absolute URLs.
Any and all help is appreciated. Thanks.
You are creating a web application, which can be available on internet and can be accessible throughout the globe. In your example, which is not working, you are referencing a image file from local file system from your own computer, inside a web application. Your Web application is running under its own process and under its own account/user(IUSR in case of IIS) and your local system is running under a different process. so the two can't talk to each other like that.

Adding User Controls To Web Page in VB.Net Web App

I have followed the setup instructions at this link Adding Controls to a webpage
However, for the 2 weeks that I have been studying vb.net, I have yet to be able to add a drag and drop form or control element on the page as all options are grayed out...even while in design view. Is there a setting I am overlooking? It doesn't make any sense that there would be tutorials on how to do the exact thing I am trying to do, but for some reason, it does not allow me to do it on my setup. Please help!?
Ok...rookie mistake. I figured it out. I was still running and debugging the application. Must stop the application from running and then all form controls become "addable".
Hope this saves someone time.

Multi-page/user control Silverlight application

I'm starting a project which will contain multiple pages tabs style. I.e. you have a footer of the application and it's header. Header contains buttons that load different User Controls in the center of the app. I know how to swap user controls and show one or another, but, what concerns me are events from hidden controls and UI updates.
I was thinking about creating UserControls to represent each page. One would contain list of files available for download, another would contain UI of the download manager that would show end user progress of download.
In order for some page/control, that is not currently showing, to throw events, its instance need to be present. What would happen with UI updates in this case? Consider user selected files to download and added them to the download manager. Download manager is currently in the "background", basically, it's UI doesn't exist (instance of the UserControl exists though). I presume that every attempt to update the UI will end up with an error?
Or, am I over-thinking this? Now, that's all a theory at the moment, I didn't yet code a single line of code for this project because I wanted to consult with someone and start from the right foot.
Thank you in advance.
P.S. Or may be use tab control...
If I understand you correctly, you are not loading/unloading the usercontrols, but merely showing/hiding the usercontrols. Updating the UI should not cause an error in this case. What you need to the design and implement is a number of events that the container will subscribe to. The container should then trigger funtion calls to the correct usercontrol that needs to be updated. But, as you state I would prefer to use a tab control. But, the event part is still the same.

How can I load .ascx user control from console application or windows service?

We use ascx user controls as templates for documents (e.g. invoices).
Now I need to load,render to HTML, then transform to PDF these controls from windows service.
So, what's the correct way/workaround? TemplateControl.LoadControl(path) doesn't work.
To be perfectly honest, I don't know how to do this. However, if I was stuck with this problem, I think I'd download the ASP.NET MVC source, and see what they do to render a partial view (a partial view in MVC is essentially an .ascx control). The Render method on System.Web.Mvc.WebFormView might be a good starting place.
You're probably going about it the wrong way, to be honest. You should probably have your logic embedded in a library, and then have the user control interface with that library. Then, you could use that same logic to populate values on a form, or similar.
You're probably going to run into a lot of trouble trying to get the control to load, and deal with things that don't exist outside of ASP.Net, like session variables, and viewstate.
Generally, what you're asking for is a report, which is handled by something like Crystal Reports, or SQL Server Reporting Services.

Drag and Drop to a hosted Browser control

I have a WinForms program written on .NET 2 which hosts a webbrowser control and renders asp.net pages from a known server.
I would like to be able to drag, say, a tree node from a treeview in my winforms app into a specific location in the hosted web page and have it trigger a javascript event there.
Currently, I can implement the IDocHostUIHandler interface and getting drag\drop events on the browser control, then call Navigate("javascript:fire_event(...)") on the control to execute a script on the page. However, I want this to work only when I drop data on a specific part of the page.
One solution, I suppose, would be to bite the bullet and write a custom browser plugin in the form of an activex control, embed that in the location I want to drop to and let that implement the needed drag\drop interfaces.
Would that work?
Is there a cleaner approach? Can I take advantage of the fact that the browser control is hosted in my app and provide some further level of interaction?
Take a look at the BrowserPlus project at Yahoo.
It looks like they have built a toolkit so that you don't have to do the gritty work of writing the browser plugin yourself.
If you can find out the on screen position of the part of the page you are interested in, you could compare this with the position of the mouse when you receive the drop event. I'm not sure how practical this is if you can get the info out of the DOM or whatnot.
As an alternative could you implement the mouse events on the bit of the page using javascript?

Categories

Resources