how to Print asp.net user controls in separate pages? - asp.net

I have around 10 usercontrols ( each user control has textbox ,gridview) to be displayed on a single page which needs to be printed using cutepdf.
The issue is the user controls breaks into seperate page (like textbox brteaking into pages). Is there a way to print a asp.net page selectively into separate page ?

The CSS properties page-break-before, page-break-inside, and page-break-after control where page breaks occur when a web page is printed from a browser.
Assuming CutePDF accurately represents the pages as they would have been printed, these should help you achieve page breaking the way you want and avoid breaking pages mid-control.
(Of course, if something, like a table, is too long for one page, a page break is inevitable. But these CSS properties will at least give you some control over how they occur.)

Related

ASP NET WebForm application Show <ElementName> is not valid

I'm working on a .NET WebForm app which has a master page. The .NET can not recognize many elements in the aspx file. For example it say Label is not a valid asp element and then says most likely reason is a malformed web.config file.
I double check my web.config and all looks good. The other webpages do not have same issue. The interesting thing is I do not have this issue inside the MasterPage.
I also tried recreate the page from scratch but still having same issue.
I'm using VS2019. Framework 4.6
You have to provide some sample code and markup. Also, if you have a master page, then that is a huge deal also. As a general rule, asp.net controls you drop on the page are able to be used from code behind. However, the code for the standard page(s) that we use as a "child" of a master pages means that code behind for the master page can easy use controls in master page. And code behind for the page being displayed in that master page ALSO can freely use its own controls. But controls between the master page and the working child page is VERY different matter.
And of course controls dropped into a repeater, or say listview (or even gridview) means that the one label or text box control is automatic repeated over and over. As such, you have to pull/get/use the one row out of that data bound repeating control, and then from that one repeating row grab the control in question.
So, saying I can't start my car, or I can't use or get a control?
We need more information as to the context of what control, where it is (in the master or child), and is the control perhaps nested inside of a data bound repeater, listview, gridview etc.
so, edit your question - add some details as to the markup, where it is (master or the child page), and we can help.
So, as a general rule, code behind in master page is free to use controls in the master page.
And in the web page you created, once again code behind is free to use controls in that page.
It can be more difficult to say have code in master page, and have it reference controls in the child page that is being displayed. But, then again, it is VERY rare that code in master page would need to reference or play with controls in the child page, since a master page will (usually) just be your main navigation bar - and it will be the same for many if not all pages you display - hence you master page really can't know what controls will exist in the current child page being displayed.

ASP.NET: Creating multiple printable pages and print them with one click

I want to achieve the following: create a number of instances of the same web page, each of the the pages displaying slighty different data (like customer name, address, ...). These pages should be printable with as less effort for the user as possible. The problem is that if you call the javascript print-directive on every page, the user would get a ton of the PrintDialogs.
One solution to solve this problem would be to create those print pages dynamically during runtime and put them all on one page, separated by page breaks (so the user would only have to confirm the print dialog once). This solution has the huge problem that I can't use the Visual Studio designer to put my page together.
Another possible solution would be to build the template of the page in the designer, dynamically fill in the customer-specific data into the corresponding controls for every page, and then somehow chain all the resulting pages together to one long page; again separated by page breaks. But I dont really know how to do that....I tried to use the Render() event, get the HTMl code and then duplicate it, but I didnt have much success with it.
So, any guidance for the Render() approach or any other solutions would be very welcome!
Is your data in any form of list? Can it be put into one? Not necessarily all of it, but an ID per desired page, or something similar? Sufficiently that it could drive a data-bound control?
You could use a Repeater control on your page to build out your "pages" according to a template. Page breaks could be achieved with CSS styles. Then you'd have just one (long) page you had to print.
You could even make your "page" a UserControl to make data-driven variations in rendering easier to organize.

Stop Master page refreshing while navigating between pages?

I'm using Master Page in my ASP.net application, in the master page I put a ContentPlaceHolder in Update Panel to support AJAX in child pages, the question is how to stop Refreshing "master page controls" while navigating between pages?
For navigation between pages I tried to use Response.Redirect, windows.location java script with no success, shall I use the Frames or IFrames instead of Master Pages to stop Refreshing?
any suggestion to solve this issue will be highly appreciated, Thanks in advance...
If you don't want the page to refresh when switching between "pages", you will not have any good solution using master page. As others have said in different words, the master page is just a common "template" that is used by different pages. The navigation between is just like calling different pages, and of course will reload the entire page, including the master page content.
A sollution I have used with Ajax is
to have each "page" as a user
controls, and put them all in an
UpdatePanel with visible="false".
Then for navigation between "pages", switch
visibility for the user controls
to show the right "page" control.
The alternative is to use iframe.
Neither of these solutions use MasterPage.
The MasterPage concept was designed to simplify a common look before Ajax was introduced in ASP.NET. After Ajax became popular, the demand for not refreshing the entire page has been more common.
A masterpage is nothing more than extending your "normal" page with (most of the time) the default layout of your application. The master page and the contentplaceholders are rendered as a full html page. When you navigate between pages it is the normal behavior that your whole page refreshes. This is how the web works.
Working with an iframe could solve your problem. However that has some other side effects:
The whole masterpage isn't useful anymore. The content around your iframe is the "masterpage".
With a masterpage you actually browse to another url, you also see in the url bar of your browser. When you work with an iframe you navigate within the iframe to another page. The url in your browser will stay the same. When the user of your application hits the refresh button it always starts again at the default page you assigned to your iframe in the html. Of course there are some workarounds
Anyway. It really depends on your application. There are multiple solutions to work around the refresh behavior.
Having a structure like the one you've explained:
Master
Child page 1
Child page 2
...
Then you cannot prevent the page from refreshing when you switch from page 1 to page 2 etc. for you have a single "page" entity (master content + selected page content) when it's rendered to the browser.
If you want to switch betweent different app views inside the very same page (so to prevent a complete page refresh) you could use a single page (the Master becomes quite useless) with an updatePanel in which you load the different views.
You can also use iFrames, but if you have to handle any type of communication between different parts of the page (some of which are inside iFrames) I would personally advice not to use them.

ASP.Net Page abstraction

We have a win application that shows a web form in a web browser.
In order to get data from this web form we are using a hidden text box and get its text using HtmlDocument object of web browser control.
I want to make an abstraction of this web form that has this text box element so that other forms can use this abstraction.
I made a web control and put the text box on it.I thought that if I put this control on my page it would have the text box.When i ran my application I noticed that the text box had been rendered but had its control name in its name (WebControl$TextBoxName) and its id(WebControl_TextBoxName) and the win app throw an exception since it couldn't find the element by its id(TextBoxName).
So here's my question:
How can I make an abstract web form/web control that has some elements on it and I can use it to make my final forms have these elements on them? (their names and ids should not be changed)
Thank you for your help
dotNet 4.0 supports static id's so they don't get mangled, read up on Client Id Mode
Alternatively, you could override the render of your control to output a standard html hidden form field with whatever ID you want, and then also add a custom property that will return the textbox that will hide the fact that it isn't an asp.net server control.
Though I've never used the browser control in WinForms, I think what you want to use is a Master Page. Assuming what you're rendering in the browser control is an ASPX page, create a Master Page with the hidden text box that you want to grab your data from, and tell all of the pages you want to have that common control on to use your Master Page. When the page renders, the control id will then be "ctl00_TextBoxName". There is no way of getting around the ID concatenation, since unique IDs are needed and that's the only way to guarantee uniqueness with all the nested control abilities of ASP.NET. However, doing this will guarantee you always have that control named the same on every new form you create that inherits the Master Page. Hope that helps!
In summary (because who reads paragraphs?):
Create Master Page
Place your common control in the Master Page
Have your Form inherit the Master Page
You can read up on how Master Pages work in MSDN's Documentation.

What is the best way to use links and anchors to toggle visibility in ASP.NET?

I have a page which is used to display numerous forms for the user to fill out and get reports generated. Each of these forms is inside it's own ASP:Panel control so that I can toggle the visibility of the form (so that only those with appropriate permissions get access to the reports they are allowed to).
The client has now requested a "table of contents" like area on the page with hyperlinks pointing to each of the forms (so that they don't have to spend time scrolling the page to find the particular report form they want). This is easy to accomplish using standard <a href="#Area"> and <a id="Area"> tags. What I am now looking for is a way that would allow me to hide the links of reports that the user does not have access to.
I was first thinking of using the ASP:LinkButton control, but I do not want any postbacks to occur from clicking the links (that would be very unnecessary). Are there any other methods I could use to accomplish the same goal? I am looking for something which would make it easy for me to toggle the visibility of the corresponding link at the same time I am toggling the visibility of the panels containing the report forms (done now from the code-behind).
Note: Using VB as the language
If you use link controls you can just show or hide the link bases on the visibility of its related panel.
Link1.Visible = Panel1.Visible
I was first thinking of using the ASP:LinkButton control, but I do not want any postbacks to occur from clicking the links (that would be very unnecessary)
I disagree. You're talking about redrawing most of the page each time a link is clicked, making a full postback appropriate from a technical standpoint. Additionally, users are conditioned to expect a round-trip to the server when they click on links. That's what a hyperlink normally does. So it's also appropriate from a user-experience standpoint.

Resources