I am working on asp.net application for reporting. I need to develop round about 50+ reports. On each report I need selection criteria that may contain start-date , end-date, name , company etc on almost every .aspx page. these controls can be of type like dropdown, textbox or calender etc .
Any idea to use one editable + shared (not 100% same) web form on every page.
Using ASP.NET custom controls will allow you to create a module that you can insert into all of your pages.
You can also check this out to get you started more quickly.
http://www.codeproject.com/Articles/1739/User-controls-in-ASP-NET
If you want to make it similar but not 100% same for all apps then just create public properties that you can use to adjust control properties on different pages. For example if some text box should be visible on some page and not visible on other just create a public property in your control named something like EnableTextBoxABC
You can create ASP.NET Custom Controls.
Related
We are using VMware clarity wizard to render wizard pages dynamically and we need to have custom logic to access the current page id/step id of the wizard for validation and other functionalities.
When trying to access page of the wizard, using pagesCollectionService and navService, we are getting the id's correctly for the first time e.g clr-wizard-page-0, clr-wizard-page-1 etc.
But the Problem is on click of cancel/submit from the wizard, the wizard id's are not getting reset, that is when we again open the same wizard the wizard page id's are in continuation to the previous id's
e.g :clr-wizard-page-4, clr-wizard-page-5 etc.
Is there a way by which we can access the page of the wizard by using any other property.
Note: Wizard pages are dynamically rendered using json
Attaching image : page id's that come up when we open the wizard for second time
enter image description here
Adding more information,
Please find the stackblitz link for more details:
https://clarity-light-theme-v013-phyhyk.stackblitz.io
Here we are rendering wizard pages, driven by config
For every wizard page we are displaying angular dynamic forms, where config contains all the information for the form fields .
Since is being called inside a for loop, we need to have a function where on click of next/back or on click of step of the wizard we should be able to validate the current form fields and store the current form fields value.
I have added (clrWizardCurrentPageChanged)="resetFormValidity()" and on every page change i am trying to retrieve the page id using wizard.currentPage.id, but the id's are not getting reset and when i access the multiple times, i am getting incremental id's : clr-wizard-page-4, clr-wizard-page-5 etc.
We are using the below versions :
"#clr/angular": "0.11.30",
"#clr/icons": "0.11.30",
"#clr/ui": "0.11.30",
Is there any other way where i can determine which page it is currently, so that i can compare that with config and continue with validation and form submission.
The Wizard has a property called currentPage which will tell you the current page. The public methods of the Wizard are at https://v2.clarity.design/wizards under the Wizard Deep Dive section, which might replace the need to inject and use the internal services which aren't meant to be used directly in applications (from what I understood in your message, an isolated demo would help greatly).
#ViewChild() wizard: ClrWizard;
get currentPage() {
return this.wizard.currentPage;
}
I'm building custom .NET web user control for Umbraco, which looks like single page, with a sidebar (which holds IDs of content items) on the left side of page, and two different content views(which have content by id displayed here) to the right of it.
The thing is, i don't know if this is possible to do something like masterpage/childs principle(in terms of this web user control), so i'll have something like "Master page" with this sidebar, and will render one of two child views to the right of it, depending on id selected from sidebar?
Or maybe there should be some workaround used here?
Will be much appreciated on any help here(like information about how that can be done, what information shall i seek for etc.), as i'm completely new in this kind of stuff.
From what I know, what you could possibly do is have your "master control" set up in your web user control, and then dynamically create one of two custom controls based on the values you choose from your master control. This is also known as a Master-Detail solution (provided a link).
Tutorial 10: Master/Detail Using a Selectable Master GridView with a Details DetailView
If each of these controls was a user control in itself nested inside another user control, you could for example have three web user controls: Master, Child1 and Child2.
Using code-behind, you could easily create dynamic controls based on those you select from your Master control using Events to the "container page". Using these events, you could dynamically create your user controls/pass them variables, and so on.
Here are some articles about events, if you are interested:
Events in User Controls
Events in ASP.NET Server Controls
If you didn't want to dynamically create your controls, it wouldn't be difficult to bind them on demand dependent on the variable from your Master control, and hide them if they are not being used/bound.
You could also use the public properties of a control you define yourself. So say you have your Child1 user control, you could define a public property in the code behind. You can access this in design-time as well.
public int SpecialID { get; set; }
I want to be able to load a customized log in page depending on a couple of parameters passed into the querystring.
Each customized login page needs to be able to dynamically display log in errors and possibly have other variables passed in.
Let's say the dynamic login page looks like this (over-simplification here):
<form>
<% if (has_errors) { Response.Write(error_msg); } %>
<input type="text" name="email">
</form>
If the aspx page loads the file like this:
Response.writefile("path/to/custom/page");
the code shows up in the output and doesn't get processed. I have tried other ways to load the file contents (something similar to classic ASP includes) but get the same results every time.
I could have all the custom pages set up as user controls, but I need 100% control over the css, js, and html - and the documentation I read here indicates that I won't have that level of granularity.
link text
PLUS - I'm stuck in a .net 2.0 environment - so .NET MVC is not available to me
Any help/suggestions?
but I need 100% control over the css,
js, and html
You won't get 100% over the page but you will have control inside the User Control instance. Also, many times, you can override these technologies like CSS, from within your control.
In the end because all controls are solified into one big HTML page you will have the same level of control as you would in any single web page with client-side technologies.
You can build a Web UserControl to represent log/in and then include an instance of that control onto any page, in any place, across multiple pages if you wish.
(See the Topics on that MSDN help page about how to create and use it).
Other useful references (these are various angles on the same subject).
Creating a Web user Control in .NET
ASP 101 - User Controls
This should provide a good start to keep looking, if this is the kind of info you think you need.
Internals
The User Control can have its own logic, access the browser querystring, access the page Session, Application, etc. pretty much anything it needs to know for itself to work.
Object Oriented
Additionally, because a User Control is also an object, you can add your own public methods and properties to it through which you can interact to communicate with the control intance on the page (just like you interact with other web controls like Button.Text="click", TextBox.BackColor = System.Drawing.Color.Blue, etc).
Other Options - Dynamic control loading
You might want to consider loading controls dynamically at runtime using the Page.LoadControl(..) method:
Loads a Control object from a file
based on a specified virtual path.
MyControl myControl1 = (MyControl)LoadControl("TempControl_Samples1.cs.ascx");
PlaceHolder1.Controls.Add(myControl1);
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.
If they are different, under what circumstances should we decide to use either approach?
Also, what is the advantage of ascx over aspx?
user controls are a form of custom control, that gives you a visual designer. They are ideal for use when you want a reusable control within the same web site. (It is possible to create and package user controls as seperate assemblies but that is beyond the scope of this question and I know has been asked on SO).
A custom control is typically used to refer to a Web Control, or a Composite Control which is specialized form of a web control. These controls have no designer and are usually implemented in seperate projects from your web allowing them to be reused accross many sites.
Now your second question, ASCX and ASPX are two different things. ASCX is the extension for a User Control, where as ASPX is an ASP.Net Page. You cannot use an ASCX by itself it must be placed onto an ASPX or Master page.
One way I like to use user controls is I have for example a very complex page which have 7 tabs, 5 of those have grids, of those grids three of them are identicle. Well what I can do is create a seperate user control for the content of the tabs, this now reduces the code I need down significantly (Since three grids are identicle except for the data).
Further more it allows multiple to work on various parts of the page, and it helps me keep everything straight since I am reducing the complexity of the page. You do not use User Controls instead of Pages, you use them in conjuction with a page.
Edit
You do not use ascx over aspx. You use ascx to complement. For example on my site every page has the same footer, but I don't want every page to derive from a single master page. I can create my footer as an acsx control and put it in each of my master pages.
Another example, I have a form that lets a user enter three different date ranges. (And we have other forms). So I put the logic to enable a calender button, and a text box that when clicked on opens up the calender, in a user control. I can then reuse that user control in all my aspx pages.
Custom controls are control build entirely in code. The pro is that you can put them in libreries, add an icon to the toolbox and other fine control.
User controls are more easy to do, and in general is a way to encapsulate things to simplify other pages or when you need to use the same markup in several pages.
The advantage of controls over regular aspx pages is that you only need to do some part of the markup (not the whole page)
User Controls/Composite controls
User controls that are made up of other ASP.Net or custom controls. They are usually quite straight forward and can be created quite quickly. They Are generally not shared across projects however there are some tricks that can allow you to do this.
Custom controls
Custom controls are controls that you implement the UI by creating everything from the HTML output to design time support. Custom controls take much longer to make. You must use either Web.UI.Control or inherit from a sub control (Textbox for example). Custom controls are compiled to binary format to allow them to be distributed more easily. Since they are compiled they can be referenced from the toolbox in visual studio.
There are 2 main advantages to using a control in an aspx page. Encapsulation of logic and reuseability.