ASP.NET Dynamic Data and uploading files - asp.net

I am developing a small, internal-use only web application. Given its simple nature and intended audience, I decided that it might be a good opportunity to use a ASP.NET Dynamic Data project to get things up-and-running quickly. So far so good, except for one issue that has me reconsidering the whole plan:
I need to be able to upload files through the website. There is an entity in the model that represents an uploaded file. This entity has properties for the file's contents, the file name, and the file's content type. When uploading a file, all of these values are obtained from a single FileUpload control.
Since a FieldTemplate has a one-to-one association with an entity property, I decided that I needed to create a custom EntityTemplate for the File entity. At this point, I have created an "edit" template for the entity that has a FileUpload control. What I have not been able to figure out is, when the user clicks the 'Update' link, how do I get the data from the FileUpload control back into the entity and (ultimately) into the database.
Any advice or guidance is much appreciated.

you can add other values to the dictionary in the ExtractValues method of the FiedlTemplate, what you have to be aware of is that if those values also appear as rows or column in the page template then they will overwrite the values you added. I usually scaffold them as false and then only referance them in the custom field template.
Note you can access their initial values from the Row property in the OnDataBinding event, you can cast the property as the actual type or use an interface added via buddy classes.

Related

How to keep shared data without using singleton in Xamarin.forms

I have a ContentPage with a ListView. I'm navigating to this content page using another content page's button. This button shows the list item count. I have ViewModel connected to each content page. I can update the count when add items to my ObservableCollection since field is adding not from the list page. But when I delete an item from the list view, I want to update the count in that time as well. How can I keep this ObservableCollection as a shared one between these 2 ContentPAges? I know using aSingleton class we can do this. But since my code should support for unit testing it seems I cannot do this.
What is the best way to make this ObservableCollection shared among these content pages?
If I understand correctly you need a single data repository to be shared between multiple ViewModels. Which means that you need to keep a single instance of the repository somewhere in your code base. Depends on your project setup this repository can live in the IOC container or as a simple property within the App class or elsewhere. Also, depends on the collection data type you also may need to persist the data to SQL, local storage or etc. This way it will be trivial to access the collection from any ViewModel in the application.
However, since I don't understand your intents fully, there might be other solutions. Like passing the reference of the collection to the next page and etc.
If the only information you are wanting to share is the actual count of the items in the list, you could use the MessagingService that is build in in Xamarin Forms.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center
So in your example maybe create a class that holds all the info that you want to share and in one page do a
MessagingCenter.Send<ShareInfo>(...)
So you can pass data.
And in the other page do
MessagingCenter.Subscribe<ShareInfo>(...)
To receive the data and use that to update the button count.

Asp.net setting some context for a Custom UITypeEditor from parent form at Design Time

Trying to craft a way for our designers to create custom asp.net webforms for our customers. The basic idea is that we have a general set of fields that can be saved, with each customer using a subset of those fields, each customer may have it's own names for similar concepts (ie one customer may use 'patient' and another 'customer'). Staying in customer context will help the designers build the correct form to meet the customers needs.
Now to do this I need to get as much as I can into the design experience as possible. I have a set of custom controls that derive from base controls like asp:TextBox and implements an interface to allows me to iterate over the controls and insert values from a data store, or fetch values to persist (Done). All of these controls need to be bound to a data point in my record object. I have a metadata system set up to allow the binding, but where I am running into trouble is in getting the list of available fields into a UITypeEditor. Namely, I haven't figured out how to (at design time) set the customer context on the form, and then access and use that value on each controls custom property editor (also at design time). Is this possible? Am I looking at this problem the wrong way? A form always has 1 and only one customer context. So in my forms project, each form will have a different customer id set to it.
As a second question how can I debug these editors? There is an expectation of web context in the editors, but there is no asp.net property grid. and even if there was, the editors are winforms components that wouldn't run in a browser.
I can include the code I currently have if it simplifies the problem, but even a simplified example is a half dozen classes.
I resolved these issues, posting here in case a general solution can be useful to anyone in the future.
I was able to get around this problem a bit by going the other way. My parent Page iterates over it's controls, and sets the CustomerId on all the controls that implement a specific interface.
As for debugging. Some refactoring got me to a place where I can easily swap out the webforms specific parts of my implementation for testing.

Need example of a web form editing a parent entity object with children

I'm working on an "edit" page for an object. On this page, I would like to have something like a DetailsView allowing editing of properties of the object as well as a GridView with children and allowing for simple Add/Edit/Delete of the children. The updates to the parent or child objects shouldn't save to the database until a Save button is clicked. I'm asp.net web forms and Entity Framework
As a simple example, imagine a Project object with a collection of Resources. I am building a page that allows a user to change Project properties such as ProjectName in a DetailsView as well as add/edit/deleting a Resource in a Gridview below. One Save button at the bottom saves everything.
I've found examples of this in MVC, but am having trouble finding a web forms example.
I am not able to code your application for you but I have accomplished this using one of two variants of the same pattern.
Create a record object for your children that is serializable and maintain that in a ViewState based List. If the data is significantly large, consider maintaining it in Session and use a unique key to your Session object (such as a GUID assigned at Page_Load) and stored the key in ViewState.
When your use is done editing the parent / children, you will have to resolve the changed to your ViewState / Session based objects to those stored on disk.

ASP.NET and XML for each hit to website

I have a question to understand the concept of ASP.NET with each client browser.
I am trying to update the XML on server when a user hits a particular page on my website.
This page is dynamic, but too large so I want it to load using an XML file also I have several drop downs on the page when user changes the value in drop down, I need to refresh the data based upon the selection, additionally my drop down is a custom designed here I do not get and selectedIndex change event.
So I'm using JQuery to get the changed value in my drop down and planning to read XML from jQuery and display the data.
But since the XML is updated on hit of the page on server, I want know, if multiple users hit the same page, will the data displayed as per each users selection or it will mix the data and show the last hits record.
If I'm not mistaken about your question, you basically ask the following:
You have an XML file, which is updated, on some event from user. The page, which is displayed to the user is based on this XML file. What info will users see, when multiple users are working with the application?
This greatly depends on how you are using that file. In general, if you try to write that file to disk each time, users will see the last update. Basically update from the last user.
However, you can synchronize access to this file, write the file on per-user basis and you will see a per-user output:
<data>
<selectedData user="user name">123</selectedData>
<!-- and so on -->
</data>
UPDATE:
For anonymous users this would not work well. However, if you need to store the selection only for the current user, you can use SessionState and not an XML file.
I would like to introduce a new way that it helped me to answer my above question.
What i did here is
on Page load we added all the information related to each section in different hidden fields.
suppose i have three section with my custom drop down!
What exactly we implemented is that on click on my custom drop-down, we separated the values from the hidden field with the separator we entered and displayed the data accordingly, small part of logic but it helped in displaying the data without post back.
and Jquery helps a lot to me for just changing the inner html of my block.

How to create a custom ASP.NET control with automatic validation

I am building an ASP web site that contains a large section that represents a database front end. I need to build forms to manipulate the database and obviously there would be much repitition i.t.o the type of input field and rules pertaining to the field. For example there are many tables where I have take on varchar(n) fields that could be required or not.
I was thinking to build a set of custom controls that would contain a label naming the field, an edit control (text box for example) and validators for the edit control. The custom control should automatically get the field length and set the MaxLength property as well as determine if the field is a required one and ad a RequiredFieldValidator etc. So when I create the custom control I would do something like this:
<user:UserControls_TextFieldEdit LinqObjectType="Franchise" FieldName="FranchiseName" runat="server" />
There must be a way to achieve this but I haven't I been able to find any controls/libraries that do this. I don't know how to get the field information armed with only strings representing the Linq entity name and field name.
Any help/suggestions would be appreciated.
I am using ASP.NET 3.5 and Linq.
Thanks,
Gerhard
Is Dynamic Linq what you need?

Resources