.Net - Best practice for element id's in repeating page sections - asp.net

I'm not sure how to boil this question down into a sensible single-line title. I'm also new to .Net.
I want to build a web-page version of an invoice, but I want each page of the invoice to flow down the page, not be paginated. The header of each section will be the same, but the line items and the footer will be different.
I've done this before by writing html to a stringbuilder and then outputting it to a literal control, but I think there must be a better way. I'm just having a hard time conceptualizing how to do something like this with server controls because of the fact that the ID's need to be unique.
Can someone point me in the right direction here?
Thanks!

You can create custom control and give it some properties that you can modify how you want and add the same header and footer to the control. Then use it on your page how many times you would like. Check out tutorial here:
http://www.codeproject.com/Articles/87474/ASP-NET-Custom-Control

Related

MVC: How to create a common Section to be shared by multiple views

I am exploring the use of Sections to create optional content in my site's layout, as explained quite neatly in ScottGu's article here:
http://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor
However, what I'm trying to do is add a sidebar to the views related to a specific controller, where the sidebar contains static information relevant to the controller. The data won't be tied to the model - it'll just be some links to external pages, and some static 'helper' text.
I don't want the Sidebar on every page / view - just on some views (in my case, it's the view related to a specific controller).
What I don't want to do is have to declare the same Section and content for each view that needs this. I was trying to find some way of creating a 'shared section' - that I could reference neatly in the views that require it, and pass back to the _Layout when the View is returned by the controller.
Partial Views seemed to be the way forward with this:
Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine
But I'm not sure if this is the right way to go about this, or if there's more succinct way to achieve what I'm aiming for.
I have been searching for answers on this, but as ever with this sort of thing, I am 100% sure I am not using the correct terminology in my search attempts for this - so apologies if this is duplicate post, basic stuff, or has already been answered elsewhere.
Any pointers on this - even if it's just to give me some direction on the terms to search on - would be welcome !
I've not provided any example code here, but could possibly knock something up if it helps articulate things.
Cheers
It sounds like you need Layout nesting, rather than sections.
You can create a master layout, then have a layout that contains the sidebar, making it's Layout property point to your master layout. Then, you can choose which layout for your content pages to use, simply by specifying Layout = Master.cshtml or Layout = Sidebar.cshtml
I think the approach outlined in the link you provided is very feasible.
Another alternative, depending on the complexity involved in getting the sidebar in your layout, you could create a separate layout.

How to set dynamic markup to a transformation wrapper in Kentico

I'm very new to Kentico and asp, I'm coming from a php/Wordpress background into this. I'm working on a Page Template that has an optional Carousel in it. I'll need the content of the carousel which I have set as a Document Type, but I'd also like to be able to have a Settings Document type in which they are contained. In the Settings Document Type I want to be able to control what kind of wrapper goes around the whole thing, using a form to do this. I've played around with Hierarchical Transformations, but can't seem to get them to work. At best, I'm able to display markup from the transformation, but the variables set in the Settings Form won't to come through.
Does anyone have any idea as to the best way to get this to work the way I want it to, or is this even possible? I only have access to the CMS and have no access to the file structure or anything like that. I've looked through pages of Kentico documentation, but it seems vague and I can't seem to find any examples of anything close to what I want to achieve.
Update: I've finally somewhat figured out how to make this work with Hierarchical Transformations, but I'm still having an issue with the Opening and Closing Wrappers which I set as Header and Footer Transformations. For some reason these tags appear twice, one within the other. The outer one does exactly what it's supposed to do, but the inner one doesn't take the variables set within the form. Anyone have any idea how I can just display this once?

ASP.NET website structure / flow

ASP.NET, web form model.
Is there any sample code/site that demonstrate a couple samples for regular website patterns/ templates? Like if I want to use tab to switch between different pages, should I put the code in a single page or in different page, and treat each tab as a page.
Or if in a search page (just a single search bar and button), should I display my result panel in same page using dynamically enable the result panel, or just to another page?
I want to find a general design pattern/ template. Please advise, thanks.
I don't know if this answer will be helpful to you or not. Correct me if I am wrong.
You are specifying demonstration about web designing. It seems the functionality you want is clearly saying to choose from weather you want to use AJAX or not. I suggest why don't you use jQuery Framework for all this functionality.
I would give this a read and consider what best fits your application and your programming style, no one size fits all with paterns.
http://msdn.microsoft.com/en-us/magazine/dd252940.aspx
After you have a general idea, head over to google.com and look for the patterns that catch your eye for simple tutorials
Edit:
For the specific question about whether you should modularize your code. The answer is almost always yes. If you think there is a chance that the component will be used somewhere else then doing this a head of time can save you a lot of headache later. This practice also makes maintaining a lot easier because it gives a clear scope of what could be causing a bug. Instead of having to look threw an entire page of unrelated code for things changing state unexpectedly in the page life cycle.

alternative of usercontrol

Is there any other alternative of usercontrol other than webpart and iframe, Which i can use in my asp.net application.
thanks in advance.
Don't know what you are trying to achieve but at the top of my head I can say you can use an update panel to act as a type of iframe to load another page inside your page.
User control is already as abstract as possible: it's final and ultimate goal is to send something to the browser, based on parameters you give it from the server side. Label has Text property that once set, send <span> tag to the browser with that given text. Panel has collection of children that when set are sent to the browser wrapped in <div> element. Etc Etc..
So the direct answer is: no, no alternative.
However, based on your comment, there might be a way to improve the performance.. what control you currently have? How user can customize them? If you can explain better the scenario and post some relevant code it would be great.
Considering your comment on the question, Using usercontrols along with placeholders and some jQuery plugins OR simply web parts controls as containers is fine.
No need to change it unless you have a problem with it. Then we might discuss other options like Custom Server controls etc.. but those also have their issues, etc.. so it's always a balance.
If you have no problem and want to check whether this is the right thing that you do or something else, then I think the answer is, yeah. Unless you have specific issues, this way seems OK to go.

OpenXML: Creating reusable Content Controls with binding

I need to attach specific XML to a word document so the elements will show up in the right places. This I can do with OpenXML SDK.
The thing is I want too be able to define the Content Controls already bounded in some sort of template so other people can create the real document template the xml will be attached to. Ok not sure people will undestand what I mean so I will explain further.
There may be many different document templates that will use the same XML data and so the same Content Controls. It's up to someone else to create the document.
Scenario: Some dude that's not a programmer needs to create a new form for the usual info because of some changes ( new layout or somehting ). This has nothing to do with the XML info, that stays the same.
Optimal solution for "some dude" would be to create the document in Word and drag the Content Controls into place ( or some solution similiar). Then when the XML gets added to the document there is no problem as the Content Controls are pre-binded.
Now there are a few points here:
1) Can Content Controls be pre-binded? If there is no XML at the path won't it just stay empty without problems?
2) Will binding Content Controls to CustomXML's like this still work in future versions of Word because of the i4i lawsuit?
3) Is there perhaps another optimal solution better then this?
Thanks in advance.
EDIT:
To be more clear. I wan't to create Content Controls that would have some name to identify them and a databound xpath. However at that moment there is nothing at the path.
Another user comes in and creates a form, decides the layout on so on, and then adds the Content Controls into the places he wants the info to be.
Later on the info for item X is requested using the new form. So a copy of that form will be taken and the CustomXML will be added into the Docx file. Now because the XML shchema was known beforehand and used when deciding the paths for the CC's this XML data will be bound to the Content Controls.
One great option would be to use VSTO (Visual Studio for Office) to build a set of document templates that have your prebinding code attached. These two articles provide a good start into looking into this type of a solution:
Creating a Template By Using Content
Controls
Binding Content Controls to Custom
XML Parts
There are two threads that discuss some details of this: 1 and 2.
One of the benefits about using VSTO is that you can hook the Content Control events: Content Control Event Model in Word 2007.
If VSTO is not an option, you can always look at Add Custom XML Parts to Documents Without Starting Microsoft Office.
This should be very straightforward. Custom controls are not impacted by the i4i lawsuit and you can name them using the tag property in each control (warning - it is limited to 64 characters).

Resources