I'm making a web application, but I am not using MVC.
I have pages like: create a task, create a project, create a case...
Everyone of these requests standard information like: StartDate ( a calendar widget, etc), Start time, etc.
If, somewhere down the line, I need to change this standard stuff, say, I need to change the calendar for a textbox, I want it to change everwhere where this is used.
What is a proper way to do this sort of thing?
In the ASP .NET code it would be nice to have like:
SchedulePanel.Calendar.Date;
It does not have to be panel based or anything, but I basically have a group of controls that I need in many places.
Thanks
You can put all of those controls into a UserControl and add that whenever it is needed. Like Robert said, if it is needed on virtually every page, then put those controls into the master page.
asp.net UserControls are really idea for this type of situation.
http://asp.net-tutorials.com/user-controls/using/
Please explain more this statement:I want it to change everwhere where this is used.
If I undesrstand correctly you can put all your controls in a User Control and in code behind declare public variable and change your controls in set section
Related
I am trying to use TelerikUpload component in my application. I am very new with the blazor and I am stuck with a problem where I don't want to use #SaveURl to upload my document, I am doing the document save functionality on my button click, so when I don't use the #Saveurl property in the TelerikUpload component it shows me the 'Uploading status' which I am not able to find a way to hide or make it work.
I just want to find a way where is just simply select the file and add it in the collection.
Your help will be much appreciated.
I took a look at the TelerikUpload control. To the best of my understanding, it requires you to set the SaveURI parameter.
If you just want a control that can select files (but not do anything with them), you might want to check out Steve Sanderson's BlazorInputFile control:
http://blog.stevensanderson.com/2019/09/13/blazor-inputfile/
https://github.com/SteveSandersonMS/BlazorInputFile
My program will prompt the user for a number, i.e. 25. The program will then start the "main form" with 25 controls (textbox). The 25 (or whatever number) of textboxes (or whatever control) will need to be formatted evenly. I will also need to be able to retrieve the text (or another property if I use another control) in order, from left to right and up to down. What is the best method of approaching this?
Using WPF MVVM. In a .XAML file, create a DataTemplate with the DataType of a ViewModel that will provide the binding for your TextBoxs, lets call this the TextboxViewModel. Then using a ItemsControl element with an ItemsSource of TextboxViewModel. You'll be able to instantiate as many TextBoxs as you want and be able to get the result by browsing through your list of TextboxViewModel.
Supposing you are using Windows Forms here.
Dynamically create the X controls and add them to the Controls collection of your form. To ease the access to them you can store their reference in a List and set some event handlers too, depending on your needs. You just need to calculate their positions while you add them.
If WinForms, this is exactly what the FlowLayoutPanel is for. Just add the controls to it and they will arrange themselves automatically, wrapping down to the next row as needed. As Mihai already suggested, you could also keep reference to those controls in a List.
Another option would be to use a TableLayoutPanel. It's a little more difficult to learn and use, but is much more flexible and powerful.
In my page, i got two column and multiple rows. The first column contain the label such as question for the 1st row, and the options for the questions. And the second column is the textboxes. When i click on add button, i wish to add those controls to page which subsequently allowed me to add the value in the texbox to database. I did some research but most of them uses javascript or datatable. Is there any other method?
You don't specifically say what type of .net development you are doing, and your question is tagged with asp-classic, which I doubt you're using. [If you are please please stop] So I will assume you are using Web Forms.
While I don't agree with Inerdial's position that you should avoid dynamic controls at all costs, I will say it does make things much more complex and requires a very good knowledge of the ASP.net Lifecycle. If you truly want to go down that path, here is a great resource.
With that said what you are describing to me does not appear to need that and his suggestion of setting the control visibility to false is a good one.
You could create a row, a panel or a div and output the controls that you need when adding a new row and set it's server-side visibility to false whenever you don't want it displayed. Then you could have a link that when clicked it toggles the visibility to true and will allow the user to add items. Once users add items they'll be displayed in your data table and you can reuse the form to add additional items.
I would also like to encourage you to consider JavaScript if it isn't an overly complex form. It eliminates an extra round-trip to your server and in general is a better user experience.
Edit: This link may also be of use to you.
I need to create a survey page with the following structure read from database.
Survey QuestionA
a) Answer1 [Radio button]
b) Answer2 [Radio button]
c) Answer3 [Radio button]
d) Answer4 [Radio button]
repeats..
The page has many questions that needs to be dynamically added. I need to store the result of the form on in an array of Question object on submit.
One way I know to do this is create dynamic UI in a table and get the values by FindControl.
Is there a better (elegant) way to do this?
In ASP.Net MVC it handles the dirty work for you with default model binders. Of course you can also create your own. Though this does not give you the automatic solution you were hoping for in ASP.Net Web Forms, my preference in this situation would be to follow a similar common pattern that ASP.Net MVC is using for it's naming convention thus simplifying it. You could then start writing code that could be reused over time. Here is a link to an article explaining the naming convention on Haack's blog
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx.
Long term recommendation is to come to ASP.Net MVC, life is just better here :)
I suggest create a userconrol that implement a question(label) and answers(radio buttons) and each controls(labels,radios) is binded to a property of your usercontrol, Then you can read questions from database and for each data create this usercontrol object and set correspond data to that property of usercontrol, And to read data from control this state doing vice versa.
Albeit you must recreate usercontrols in each post back and set default data to those.
Also you can create multiple usercontrols with different UI that inherit a interface such as IQuestion, and a factory class that create each of usercontrols depend of environment varibles.
You can use jQuery to get the selected radio buttons by the checked property and append them with the question number.
e.g. for question 1 you have
So you can get the values iterating throught the radio buttons like so:
$("input[type='radio']").checked
You could always add the controls in programmatically.
Say you have a aspnet Panel control you can perform...
RadioButton rb = new RadioButton();
rb.ID = "rbRadioButton";
rb.Name = "rbRadioButton";
rb.cssClass = "radioClass";
Panel1.Controls.Add(rb);
Excuse the harshness of the example, not got visual studio to hand at the moment to check it but I hope you get the idea. You could in essence build up the whole question this way based purely on the database. The downside is getting the values as you have to override the Render method (if I remember right, it has been a while, I do have an example if you want me to find it).
I admit it is a little overkill but it is a possible solution.
use radiobuttonlist (which you can see in the the toolbox ,it is a asp.net standard control) control for this purpose. It is up to your needs.
I have this progressbar control which i would like to be visible on several pages of my application. How to i create a "global" control like this?
Thanks
/Richard
A few questions:
What do you mean by global?
Would you like to create one instance
of your progressbar and share it?
What kind of control do you use? Is it UserControl?
Are you aware of this toolkit?
If not:
I assume that app shows the progressbar when user is downloading or app is doing work in background. Make a Popup to show it to the user. You can put it in the Resources Dictionary, and then dynamicly add it to visual tree. But wont gain any advantage.
It is not a good idea to have one control if your app is based on default navigation system(pages). I strongly advise you to use progressbar form the toolkit. Simply create an instance for each page.
You can't. But you could create a page which includes this progressbar and then show/hide/etc. as necessary.
There are two options for doing this:
a) create a Popup element in code without making it part of the element tree and assign your control as child of that Popup. Then use IsOpen=true to show it.
b) retemplate the PhoneApplicationFrame that is the root of your element tree and insert your global elements in the part of the template that is shared across all pages.