I'm making my first asp.net mvc application Forum system. I want before every thread to show picture that shows is there new post or not. Like other forums, if there is something new from last login to show one picture and if there is nothing new show other picture. I am using asp.net identity 2.0.
I am thinking to make partial view and to invoke it where I need it. But how to show picture, depending on every user, I was thinking when user log in to be invoked method that checks every thread if there is something new after last login. Where to put this logic in the mvc project, or in the db project and to store for every user last login date, and to call this method. What is the right way?
I suggest you do this in javascript as you will want the page response to be the same for all users so you can cache it etc
on each thread in your forum add a property of last updated
<div data-lastupdate="put the date there">
in the javascript set a variable for the date of the previous last login for the user
userlastlogin = date
then using jQuery (or whatever) set the picture on all forum divs where the lastupdate is greater than the last login date
Related
I have a page with a form that accepts a list of account numbers into a text box, a bulk search essentially.
This does posts to the server, does a validation exercise and then if sucessful redirects to a display page.
Currently the list is added as a GET variable in the URL to the display page. This is limiting in that it means users can mess with it and larger data sets may be a problem. It also allows for a bypass of the validation but this is accounted for.
I see 2 general solutions which are basically variations of 1 theme:
Save the list to a DB and pass a key to load this to the diplay page.
Save to MemoryCache and again pass the key to the display page.
Based on these options it seems that 1. is better if I need multiple IIS node but needs manual cache cleanup where 2. will clean it's self up but may be a problem if I need to scale. This will be an intranet applcation so scale will probably not be required.
Is there a "industry standard" approach to this class of problem. I'm coming from the winforms world where keeping track of state wasn't an issue.
I don't think you really have to redirect to the display page at all. From the controller that gets the user input and prints the result just return the View that should render the results like:
public class SearchController : Controller
{
public ActionResult SearchForAccounts(string[] accounts)
{
var searchResults = db.Search(accounts);
return View('ResultsView', searchResults);
}
}
If you really really need to redirect, I guess you chould save the results into the application Cache and later if you need to scale you could use a Redis Cache provider for example, but again you should be able to show the required view.
Whether it's Webforms or MVC, I recommend not getting into the pattern of separating validation/processing and results into separate pages.
I'm guessing that if the data is invalid you want to put it back on the page so the user can edit it. (That's a guess inferred from what you're asking.)
You can post the data, and then if the data is valid then the "result" page shows the results. If the data isn't valid then the page can re-render the input form, populate it with the original inputs, and display a validation error. That way the user can modify their original input and try again. (Just be sure to escape/unescape if you're taking user input and reflecting it back onto the page.) That's easier if the form is a partial view (MVC) or a user control (Webforms.)
I've two text boxes in one page and after those text boxes two separate search buttons, search buttons redirect to another page where user searchs and result is displayed in a grid, there can be multiple results, each row of grid contains 'select' command so that when user clicks on select of perticular row its data is selected and page redirects to previous page and data of row is displayed in textbox..
I've done so far. This is what I want to do:
Since there are two textboxes, two separate search buttons, what I am experiencing is when user selects 1st data for 1st textbox and searchs for 2nd text box then while returning for 1st page after 2nd search, 1st textbox becomes empty, What I want is that it should contain the value user has entered before.
textboxes should keep the value. If searching for 1st text box then 2nd should keep its value and if searching for 2nd text box 1st should keep its value.
I am using response.redirect method in dg_RowCommand event. I think by this page is rendering with its initial values which is what I don't want.
kindly tell me the solution I have searched so much but came up with nothing.
You can store the values in either Cookie or in a Session variable. Session variable is application specific and cookies are browser specific.
try this, for creating a session variable
Session["key"] = "your value"
or
for Cookie
Response.Cookies["key"].Value ="your value"
on the another page check first is it not null
if(Session["key"]!=null)
// use it
and same for the cookie (access it with Request object)
if (Request.Cookies["key"] != null)
// use it
use Session variable. Session["YourKey"] = your value; You can access it cross page
Update:
If I am right then you are thinking of some wizard type interface. If you can take benefit of ASP.Net Wizard control then look into this. It might help you.
Combine the pages into one, with each page(step) becoming a div or asp:Panel. hide/show divs rather than "navigate to the next page" on Click_Next event (or whatever). This way all controls stay on the same page and maintain all values when the divs are shown/hidden. No Session or other methods needed.
If you are redirecting with the Response.Redirect method in the C# Code then before you execute this redirect you can store the items in Session variables:
Session["Test1"] = test1.Text;
Sessions are maintained per user. These will be retained for as long as the application is running, but be warned that if an Application timeout occurs or the user closes the application (closes browser) these values will be lost.
I'm using ASP.NET MVC to create a web application and have stumbled upon a situation where I'm not sure what the best solution would be.
I have a users page where I am simply loading a list of users and their roles into a table. The roles are checkboxes, for example Manager and Administrator are two separate roles that are expressed as checkboxes on that row for the user.
In the far right column is an Actions field with 3 buttons: Save, Change Password and Delete.
Change Password works by opening a dialog box and hitting an action on the Controller called ChangePassword, this is a Post request as the form is in a different area and some values are set to hidden fields using JavaScript.
Delete works by calling an action called Delete which is a Get request where in the view the action parameters are explicitly set by using the values from the Model. Since these values aren't going to change I can safely do something like this:
#Url.Action("Delete", new { loginName = Model.Users[i].LoginName, username = Model.Users[i].Username })
However, the Save action is different because the save action is meant to be used to update the user roles, which the user can change by selecting different checkboxes. My initial plan was to make the Save action a Get request and have the values passed in similar to how I do this with Delete but I would need to set some sort of hidden field using JavaScript so that I know which fields are updated.
An alternative solution would be to have every table row a form and make Save a Post action and have the values from the checkboxes bound to the model on the action. I'm not sure whether this would be advised because this could potentially mean 50+ forms on the page depending on how many users I have.
I'd appreciate some advice on this issue.
Thanks
A GET request should never change the state of your application, i.e. it shouldn't delete or modify users.
I'd use the ASP.Net Membership Provider and call its respective methods in the Controller Actions.
I know this has been asked, but none of the numerous answers fit with my situation. So I will humbly ask if someone can walk me through this again gently.
Environment: .Net 4 web app using c#, javascript, jquery, sql server, and entity framework.
Question: I need to be able to allow a user to "quick add" a value into a table that is bound to a drop down box without losing values a user has already entered onto current page. I don't care if I have to do a postback or use jquery or use ajax, etc. I need the functionality first - prettiness later ... the scenario is described below if you care to keep reading. With all that being said, I would love for this to be smooth and not "clunky" for the user.
Scenario:
I have a page where the user is able to enter many pieces of information into textboxes, static drop down boxes, and drop down boxes that are bound to other tables that will all get combined and inserted into one table. Well, it never fails, a user could be filling in the page and when they get to one of the table bound drop down boxes - a value is missing or they haven't added something item yet. I would like to add a button or link or something next to that drop down box that would allow the user to "quick add" an item to the table that fills that drop down box and then refresh the drop down box so they can choose that new value from the list ... all while not losing the other data on the screen they already entered.
What I've tried:
-Tried WebMethod option. Currently, this web page calls some custom "bind" methods in the code behind to fill drop down boxes so they are not filled directly from objects from entity framework. So that means using a static method will not work for a solution because part of the static function would need to call the bind method to refresh the drop down box with the newly inserted values.
-Tried PageMethod option. Some of the other samples used Page Method settings, but my site uses master and content pages and the posts seem to state that the page method route was not going to work.
Make sense?
Add an UpdatePanel to the page. The update panel should wrap the drop down to be added, as well as the textbox/button for adding a new entry to that drop down. You would want to have a different UpdatePanel for each dropdown/button pair, if applicable.
When they click the button inside of the update panel you can read the textbox, add an extra item to the drop down, and send an update to the database. (I'd manually add the new value to the drop down rather than updating the database and re-binding, if possible, but it may not be.)
The magic of UpdatePanels will make sure that this is all asynchronous and so doesn't disturb the user working on the page.
I'm new to ASP.NET. I'm designing a user interface in Asp.NET and C# where the user can login and then launch an application. When using this application the user has to fill out a form that is 10 pages long.
So, I have used navigation menu and designed the interface in such a way where every page is different menu item and it is a static menu. The user fills out the details on the first page of the form and saves it and the data gets saved in the database.
The problem is he moves to the other page by clicking the menu tab; when he comes back to the first page by using the menu tab for that page all the filled in data is gone and he sees a blank page. I know that is how it works but I want it in such a way that in one sitting when he is filling out the data on the second page (after filling the data on first page) on reverting back to the first page he should be able to see the data that he had filled out.
What concept can I use? I'm not sure view state will be helpful in this scenario.
You should look into using the Session State variable for storing his information over the entire session. If the user is logged in you should think about storing his information that he enters in a database and having a Boolean state of "ApplicationFinished" to check if he has finished it or not. Otherwise I would have a call on each page to retrieve information from the database that has already been added, so that he can fill out information at different sittings or all at once.
http://msdn.microsoft.com/en-us/library/ms178581.aspx
Session State may be too long term for you, and if that is the case do some research on ViewState. There are a lot of different ways to tackle a problem like this. It all depends on which technology will fit your needs the best.
http://msdn.microsoft.com/en-us/library/ms972976.aspx
Also, if you're using a tab system think about using the AJAX tabs so that the data will remain on the forms even while tabbing through the different tabs.
http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/
Well, if you are write the data on database, i guess the best (fast) workaround is to add a column named "completed" to the table the hold this informations. If the flag "completed" is not setted to 1, you load the database information and fills the page controls.
When you create a new record in the database, get the ID of the record and set it on Session. If the user gets back to the first page (previous page), you can recover the information ID and load the data.
As long as you are learning new things... add jquery to the list and leverage the JQuery Wizard Plug In. It will allow you to integrate your "10 page form" into a single unit, which can then be sub divided, routed and managed more easily. You can leverage AJAX to save each step, while offering built in navigation and validation methods.
I would suggest that you switch to using client-side javascript to control your tabs. That way your form data stays in the fields when you switch back and forth between tabs. You can use javascript buttons to guide the user from tab to tab.
I've done this using JQuery. I actually had 150 fields that needed to be captured (they were all required). I group like data on different tabs and then had buttons ('< Previous', 'Next >') which would activate different tabs.
When they are done, then display the 'Save' button.
This not be what you are looking for, but if your problem is that you want all of the input of a previously filled page to show up when a user navigates back to it, and you have already saved all that information, then you can try something like this:
HTML
<input type="text" id="yourID" name = "yourName" value = "<%=data%>"/>
Then all you need to do is set data to public in the code behind. Then to get the value for data just make a call to your database.
Make sure that you make data empty on the init call public string data = ""; or whatever type it is. This way if there is no info, then it will be blank, and if there is saved info, then it will be filled in.
You can also attempt to pass all the data through params in the url like so:
C#
Response.Redirect("webpage.aspx?data=" + data + "&data1=" + data1);
Or though javascript:
window.location = ("webpage.aspx?data=" + data + "&data1=" + data1);
To get the request do this:
if (Request.Params.AllKeys.Contains("data"))
{
data = Request.Params["data"];
}
This way is less ideal though if there is a lot of data being passed.