Tool to visually create a set of controls - c#

I'm looking for a tool, plugin or whatever that allows users to design a page (by "design a page" I mean just drag controls like input, select, radio to the page and define positioning by dragging them).
Once the user is done, I have to save the page and the controls to a serialized string, or XML, or JSON, or a .Net User Control.
The user-designed page will used as an input form for information, and I need to be able to set and get the field values somehow.
It's a complex topic even to search, no clues until now.
If someone can point me a direction, it would be extremely helpful.

Sharepoint lets you to build sites with web parts, that you can create and control theirs behavior.
With Sharepoint Web Parts, you can control its information and its fields.

Related

List All Controls in a C# ASP.NET Project

Goal:
I am trying to create a permissions page that assigns permissions to roles based on the controls in the webforms throughout the application. I am trying to write the code that would create a string of controls for a given page. The page name would be passed in as a string.
This post below is very similar to what I am looking for although it was written for a windows form application in VB.NET. I am hoping to find a solution in C# and applicable to webforms. http://www.dreamincode.net/forums/topic/222439-list-of-all-controls-in-project-vbnet/
This next post also seemed to be what I was looking for but the suggestion of find in files doesn’t work as I would like the code to be more generic and extend as I add pages or controls to forms instead of hard-coded:
Get List of Controls on each WebForm in an Assembly
General Idea:
My idea is to have a user select a role from a drop down list. Then the user would select a page in the application from a drop down list. The SelectedIndexChanged would then query the webform class of the page selected and produce a grid listing the names of the controls on that page and another drop down list of permissions that could be assigned. When the user was done editing the controls and permissions, they would click save and the information would be saved to the database.
When a forms authenticated user loaded the page, the page would query the database for permissions on each of the controls and based on the user’s role and permission would either have readonly, edit, or not visible status assigned to that control. My final goal is for the end user administrators to be able to manage the permissions in the application instead of having a broad set of roles and permissions or having to do custom one-off work based on a customer’s needs. Please note that this would be the only page where I am trying to access controls on other pages.
I am trying to list all controls in an ASP.NET project or namespace since in my case there is only one namespace in my current project. I have found plenty of examples listing the controls on the current form but have not found any code that can do it site-wide.
I have also been able to list all the webform classes that I have:
How to get all classes within namespace?
But it doesn't seem that you can then go and query that class for the controls that are defined there - if someone could solve this piece, I think that would get me to the next step.
What I have Tried:
One was to instantiate the webform itself and then loop through the
controls all programmatically. This was not successful at least the
way that I was doing it. Webform1 wf = new Webform1(); I also tried
adding a constructor and a method to then go and loop through the
controls.
I also tried instantiating the webform class through the
Activator.CreateInstance I tried following the example at this page:
Instantiate an object with a runtime-determined type
Example:
Page o = (Page)System.Activator.CreateInstance(Type.GetType(pageName));
foreach (Control c in o.Controls)
lblMessages.Text = lblMessages.Text + c.ClientID.ToString() + "<BR>";
This was also not successful. It did compile but I would get a control count of zero and of course no controls.
The final method, which I am trying to avoid is a manual method of
collecting the controls on the pages in my application (which
should be static once in production) and then still having the permissions page and the administrator assign the permissions to the
role at that point.
Finally:
Any help pointing me in the right direction of being able to dynamically fine-tune permissions to controls would be much appreciated even if that includes looking at a different way to handling permissions.
That is the basic architecture of CMSs.
Using Activator.CreateInstance is on the right track. But there are a lot more into it such as persistence of control states between posts.
Please look into DotNetNuke in which controls are loaded dynamically.

usercontrol vs iframe, limitations and known problems

If this is too hypothetical and needs to be somewhere else, please let me know.
I have a project that needs specific gridviews to appear on multiple pages. Instead of copying and pasting the gridviews on each of the pages I thought creating a user control for each specific gridview or create a page for each gridview and then use iframes would be my best options.
I have not used either extensively so I am looking to the SO community's experience, are there known problems with using user controls and/or iframes when it comes to:
validation
communication between user control/iframe and parent page
ajax/updatepanels containing user control/iframe
thanks in advance
Since a gridview is essentially a user control (that's very flexible), I would first explore doing this with neither of your options. If possible, use the standard gridview and let your data layer do most the work. However, assuming you already know that... but your requirements require one or the other of your options, here are things to consider.
An iframe is easy to implement but unless your need is really simplistic in terms of user interaction, the user control will be the most flexible. Another downside to an iframe is it's size (you're essentially loading two pages). The downside of user controls are the upfront time in building them.
Based on your criterion:
1. validation - can do with either option but you'll have more flexibility with a user control
2. communication between user control/iframe and parent page - much easier with user control unless query string parms will do the trick
3. ajax/updatepanels containing user control/iframe - again user control

How to display multiple pages under tabs similar to a Browser tab retaining loaded pages

We have an application where we have a single level navigation menu with some heavy-duty pages on each link. The user can switch back and forth between these pages frequently to obtain information that he needs.
Once the page gets generated, it wouldn't change for the session. However, the page is specific to the user, hence we cant cache it.
I was trying to come up with a solution where we generate the page once, and keep it hidden in the background until its link is clicked, but haven't been able to get my head around this.
One of the ways I thought was to have multiple div tags (one for each page) on one page and keep toggling the visibility as the links are pressed, but that would end up making this single page very heavy. Someone also suggested using iFrames, but I am not really comfortable using the iFrames much and I'm not even sure, if it would be any helpful either.
Can you guys please suggest a few approaches to tackle the issue?
update: Just to clarify, we are fine with keeping the pages separate and navigate across using a standard menu bar. We were just looking for ways to optimize the performance as we know that the pages once generated wouldn't change and there should be some way to tap that benefit.
You can use Ajax tab control for this purpose
Try taking a look at this MSDN article which specifically tackles the issue of how to user-level cache. Also, it might be more manageable to break each tab into a user control. That way your ASP.NET page has just the tab control and 1 user control for each section under the tab. It makes managing tabs much easier.
EDIT:
What I would do in your case, since you say the data won't change for the user, is I would grab the static data from the database and then I would store that data in the Session cache. THe session cache is specific per user and you can try to retrieve the static data from there instead of repetitively calling the database.
Check out the ASP Multiview control. Just remember that even though the different views are hidden when not active, their viewstate is still being sent back and forth. Can be a benefit if you need to check control values across views though.

SharePoint 2007 Custom Webpart, saving data to the properties

How can I go about creating a custom Web Part that has a custom UI for editing. When the page is in Edit mode I have a special button show up "Edit" and when the user clicks on it it posts back to the page. I catch this and I want to display a custom UI so they can edit the web part properties. I need to be able to have rich text fields, and text fields that are editable and will post back so I can save them to the properties.
I'm struggling mostly with creating a RichTextField, or TextBox that I can grab the data in post back. I know how to do it if I outputted raw HTML to the page, then use HTTP.Context, but what's the C# way to do it?
Thanks!
You can check in your web part if page is in Edit mode or Display mode and render the controls accordingly.
How to tell if page is in edit mode on a non-publishing site
On postback, you can fetch the values and assign it to your web part properties. Since you are handing it custom, you will need to set dirty flag:
http://msdn.microsoft.com/en-us/library/ms157656.aspx
It sounds like you're putting a configuration UI into the web part itself?
The standard way to provide a configuration UI is via the toolpart - the tall thin window that appears down the right hand side of a page when you edit a web part.
These posts should give you a good introduction :-
How To: Custom Web Part Properties (ToolPart)
Creating a Web Part with a Custom Tool Part
(SharePoint 2003 but still relevant)

How to build a Windows Forms email-aware text box?

I'm building a C# client app that allows a user to communicate with one or more existing users in a system via an email-like metaphor. I'd like to present the user with a text entry box that auto-completes on known email addresses, and allows multiple delimiter-separated addresses to be entered. Ideally, I'd also like the email addresses to turn into structured controls once they've been entered and recognized. Basically, I'm modeling the UI interaction for adding users after Facebook's model.
Are there any Windows Forms controls out there with the ability to do something like this? Is there any well-established terminology for a hybrid textbox / control list box (no, not a ComboBox) or something that I should be searching for?
Thanks,
-Patrick
I have had good luck in the past creating composite user-controls to provide specific functionality using native .NET Winforms controls. It works pretty good as long as there aren't too many of them, in which case things start to slow down.
In you case, and this is just off the top of my head, but, perhaps you could take a FlowLayoutPanel, a Button, and a Textbox which supports auto-complete and put these together to create a control that would provide the functionality you are looking for.
If there are no addresses selected in the control (e.g. in a List<string>), then the container (FlowLayoutPanel) would only display the TextBox. Once the user selected an entry, the control would automatically create a Button with the appropriate caption and insert it to the left in the FlowLayoutPanel. If the user removes an address he/she has already selected, simply remove its representation (the button) from the FlowLayoutPanel, and the TextBox can resize accordingly. There may be issues with getting the TextBox to fill up the remaining space (I can't remember how to do that), but you get the idea. The container does not have to be FlowLayoutPanel - you could use a Panel with Docked controls, or even a TableLayoutPanel for this.
A design as I described would allow the user to delete the address by clicking on the button. However, without some other visual cues, that isn't very intuitive or user-friendly, so I would consider making the "Button" be another composite control which contains a "prettied-up" label along with an tiny delete Button (X) to the right. For this you could use a Panel control and dock the X button to the right, and fill the Label on the left. You would provide public properties here as needed to control the text and provide an event handler or callback for the delete functionality.
Once the visual stuff is working, all that is left is to provide the appropriate Properties and Methods on the main control to allow it to interact as needed with outside code.
As a simple, "poor man's", implementation you could take a look at the AutoComplete* properties of the TextBox control. You could dynamically populate the AutoCompleteSource with your known addresses and when an entry matches, add to a separate, list-style control of your choice.
See this SO article for some interesting code snippets related to your question, and my suggested workaround.
Beyond the built-in AUtoComplete properties you're probably looking at having to purchase a 3rd party control from a tools vendor.
I've not seen anything like that before in WinForms. In WPF it would be another matter - if you can use that, maybe consider hosting a WPF control within your WinForms application instead?
I think you're trying to do something similar to this codeproject article: AutoComplete TextBox
And since you mention WPF in a comment, you also have this article: WPF AutoComplete Folder TextBox (should be easy enough to cut out the folder bit of the article I'd thought).
Well, there isn't such a control. If I were you, I'd create 2 textboxes to do the job. See, a normal textbox can easily be configured for autocomplete from a list, even dynamically; however, it accepts only one entry at a time.
So, I suggest you dedicate one textbox for autocomplete, and one for the addresses. So, whenever there is a qualified email address in the first textbox, and you click enter, the address gets added to the address textbox, and automatically add delimitation.
Then you need to handle the addresses in the address textbox as objects instead of characters. Code it in a way that when a user tries to delete a character in an address, the whole address is deleted.
This is the workaround I can think of. I'll help with the code if you give it a try.

Categories