JQuery - How To Maintain The State Of Hidden UI Elements Across Postbacks
Jan 17, 2011
I'm working on a webform with various controls. Depending on user-input I show/hide (using JQuery's show()/hide() functions) bits of the GUI. However if the form is posted-back and fails validation, I want the GUI to remain in the same state it was pre-postback rather than returning to the first-load state. Obviously the ASP.Net controls retain state, but I have HTML containers that are pure client-side objects.
In attempting to design a solution I find myself heading towards the murky (and tricky-to-debug) realms of hidden form fields - more reminiscent of my pre-JQuery work than anything 21st Century :-(
I am developing a web part that uses AJAX Timer and Update Panel to perform some data check. There are two buttons outside the Update Panel on the web part that I also want to maintain during the Timer postback. I cannot put these two buttons in any UpdatePanel because they need to call Response.Write() to display some Excel data to users in their On_Click event. My current solution is using ViewState to maintain these two button in On_Load event. However, I am not sure if this is a correct solution (haven't tested it). Does any one know that during a Timer postback, if I disable/enable these two buttons using ViewState in On_Load, will it update the page properly with the two buttons disabled/enabled? Or will it ignore any control that are not in the UpdatePanel regardless where you maintain it? If my solution is not a good practice, can someone suggest other alternatives?
List<Event> events = new List<Event>(); protected void Page_Load(object sender, EventArgs e) { } protected void AddEvent_Click(object sender, EventArgs e) { Event ev = new Event(); ev.Name = txtName.Text; events.Add(ev); }
I want to add an item to the list every time the Add button is clicked, but the list is reset after every postback. How can I keep the data in the list between postbacks?
I have a grid which houses a modal popup panel. When the grid binds it gives a flicker. The modal popup panel becomes visible for a second and then hides in the grid. Is there a way I can avoid this from happening.
I am having a ASP.net application it having three pages ,page 1,page 2,page 3,when the user navigating between this pages I want to maintain the view state in page level after postbacks(i.e.) .If a user visits page 3, passing some query loads some data .then he moves to page 1 doing some entries .after that he once again moves to page 3 now I want to display the data previously available at the time he moves to page 1, same way I want to do to my three pages up to the user logging out.
I have a system that has several large objects that need to be built and populated each and every time, and these objects may be accessed quite often as well. As a strategy, caching would not be that good for me because there are potentially thousands of these objects which are fairly large. So I propose to serialize the objects to the file system and then deserialize it when I need those objects again. I have several classes that need this serialization functionality.
These objects change as well, so on the next access I check if there were any changes and then I grab only the changes and edit the object, and then reserialize the object.
My question is what is the best way to do this, since I have several classes ..
I have a custom user control which contains a asp hiddenfield object. The value of this hidden field is being set using javascript and I have verified that the value is being set properly. When a postback occurs the new value is not being saved and I cannot access it in my code.
I believe the problem is because the user control is not saved in viewstate and therefore the hidden field value is not saved accross postback. How can I make the hidden field save its value? I tried accessing it from the early page cycles and still no luck.
I am using a treeview in my master page and every node having link to its container page.That means click on any child node of treeview its redirect to another page by taking some value.
Now every time I click on nodes of treeview, its get collaps when child page loaded...
Now regaring maintain state of treeview across my web application...
and ValidateMyform will validate on each button click...
var objPost = args.get_postBackElement(); if (objPost === null || objPost === undefined) return; if (objPost.type == 'submit') {[code].....
Here I want to get back the page to normal stage(like after a full page postback)...even though after async postback the validation is still active...it should not get back to normal and its throwing errors if i enter something wrong...this is because the page is not fully refreshed on asyc postbacks...I just want get the like the normal after each asyc post back...
I tried using submit and reset to reset the page but its became to normal..the validation is still active...I have no idea what to do..
how can i maintain state in html as i am building site which has too much pages in html i can't convert them to aspx but due to some requirements i want to maintain state of variable.
I have one web application. In that, I have two pages. One is view/edit page and another one is login page. The view/edit page contains one edit button and one login button.
First I execute view/edit page, at that time I dont want to show edit button. When user clicks login button, the page will be redirected to login page, where the user has to enter username and password. If user enters both correct, again the page will be redirected back to view/edit page. This time, the edit button has to be shown to make some modifications, since the user is authenticated.
I tried this thing by using session with cookieless. It works perfectly but some times it shows web page not available. I made session timeout 120 minutes and cookieless is true. In URL session ID also available.
So, whats the alternate way to maintain user log state or whats wrong in web.config file.
In the Page_Load() event handler for one of my pages I use the new statement about 100 times equating to memory allocation for about 100 objects. As follows:
using System.Web.UI.WebControls; Table mytable1 = new Table(); TableRow [] myrows = new TableRow[5]; TableCell [] mycells = new TableCell[100]; int i; for(i=0; i<5; i++) myrows[i] = new TableRow(); for(i=0; i<100; i++) mycells[i] = new TableCell();
My question is, should all of these new statements be enclosed like so:
if(IsPostBack==false) { // Initialize all controls for page just once during the session }
Or should the Controls be freshly allocated, initialized, and added to the page each time the Page_Load event handler is called? I personally don't think its efficient to create mytable from scratch every Page_Load since all I really ever change is the contents of the table and not the table itself.
I have a simple ASP page with databound grid (bound to an object source). The grid is within the page of a wizard and has a 'select' checkbox for each row.
And when the finish button is clicked, I iterate through the rows and check what's selected:
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { // Set the selected values, depending on the checkboxes on the grid. foreach (GridViewRow gr in GridViewMatches.Rows) { Int32 personID = Convert.ToInt32(gr.Cells[0].Text); CheckBox selected = (CheckBox) gr.Cells[1].FindControl("CheckBoxSelectedToSend");
But at this stage GridViewMatches.Rows.Count = 0! I don't re-bind the grid, I shouldn't need to, right? I expect the view-state to maintain the state. (Also, if I do rebind the grid, my selection checkboxes will be cleared)
NB: This page also dynamically adds user controls in OnInit method. I have heard that it might mess with the view state, but as far as I can tell, I am doing it correctly and the viewstate for those added controls seems to work (values are persisted between postbacks)
UPDATE: Could this be to do with the fact I am setting the datasource programatically? I wondered if the asp engine was databinding the grid during the page lifecycle to a datasource that was not yet defined. (In a test page, the GridView is 'automatically' databound'. I don't want the grid to re-bound I just want the values from the viewstate from the previous post!
Also, I have this in the asp header: ViewStateEncryptionMode="Never" - this was to resolve an occasional 'Invalid Viewstate Validation MAC' message
I could also write every validation for each object separately, I have only a few elements who uses a required validation but it would be nice that I could do this in one shot instead of repeating the $("input").rules("add .....
I have aspx page and in that page i registerd ascx page. i want to access the aspx page <div id = "idofdiv"> from ascx page jquery function. i have jquery function in ascx page. i want to access idofdiv in that function.
I have created a matser page with a two radio buttons, text box and a button. Whenever user sets some values to these control and clicks the button, i will navigating him from one content page to another based on the data he has entered. The problem is after the content page load, the values selected/given in the controls(radio button, text box) are getting cleared.
1. I have couple of checkboxes and some text fields outside the updatepanel.
2. Based on the checkbox selection, I will be hiding/showing the fields to user using javscript.
3. I have a upload control in the same page which is placed under the updatepanel. When I upload the file, I will be reading the content of the file and I'm trying to load it into the controls which are outside the updatepanel. As I know the controls won't updated until unless it has been added under the updatepanel.
4. I moved all the controls outside the udpatepanel (checkboxes and textboxes) and placed it inside the updatepanel so that when the file is uploaded I can read the file and assign to the controls.
After this, I was able to assign the values to the control. However, the problem is, the state of the page (javascript hide and show) has not been retained during the postback. For example, if i have 2 checkboxes and 2 textboxes, if i click firstone, it should show the first checkbox. If I click the second checkbox, it will show the second textbox. By default, when the fresh load happens, first textbox will be shown. When I click the second checkbox (its showing the second textbox) and do the postback by uploading the file, the state gets lost and when the page load completes, it's showing the first textbox instead of showing the second textbox.
I've a checkbox with autopostback=true. If i check the checkbox the postback occurs and changes a label text. But if i click back in the browser the checkbox is not returning to its previous unchecked state. How can i bring back its state?
Can i write some JavaScript to persist the state of a control?
1) I found that my viewstate was not being persisted across postbacks for web user controls. I ensured that the Enable Viewstate property was set to true (of the page)
2) The Viewstate isnt being persisted on the 1st postback.
3) However, it is being persisted from the 2nd postback onwards.
I stepped through the code to ensure that the Viewstate had the 2 keys that I was adding on page load. However, on the 1st postback, the viewstate is empty. Everything is ok from the 2nd postback onwards.
I have a requirement where i need to add file upload contorls dynamically.Intially i have a upload control in my page and button named 'Add fileupload' and another button named 'Upload'.the fileupload control is added dynamically when 'Add fileupload' button is clicked andUpload button is used to upload the files.when i click on 'Add fileupload' button after browsing the file to fileupload control, the new fileuplaod contorl has been adding successfully but the first fileupload control is empty.Can any one please help me how the state of fileuplaod control is maintained.Here is the code