My ASP.NET page has a few text boxes and drop down boxes. When i change the selection on the drop down boxes or click any button all data available in those fields will be lost. However if i log-in to my page and just refresh it before clicking any buttons everything works as expected. It seems just like the first post back clears everything. Any ideas why it would behave like that?
Related
I have a GridView, and buttons that do actions (Edit, Save, etc). The GridView is created dynamically. Once I press Edit button, I add textbox (controls) on every cell of the GridView, with their respective text value, so it can be edited.
The problem comes when I click Save button, because when the method starts, it seems like there isn't any textbox in the gridview... so that makes me think if it's because some autopostback stuff when the Save button it's clicked.
Any thoughts about solving that?
EDIT: Clarifying what I want:
1) I got a gridview with data,
2) I put the data of each cell from each row into textboxes,
3) I put those textboxes in the gridview,
4) I do change data in those textboxes,
5) I can't save that data because when I click the Save button, the data on the textboxes deletes itself
You can't avoid postbacks, ASP.NET works with them.
When you click the save button, the page does postback and the Load event fires. In that event, you have to rebuild the page as before you clicked Save (put the textboxes).
If you don't do it, the textboxes aren't there no more and no text can be saved.
Edit: gives unique names to your textboxes, it seems non-sense, but ASP.NET need to hooks on names
Ok, so I've researched this to the end of the earth and can't seem to find a solution that works.
I have a C# application, which is basically a web form made up of radio button lists and text boxes in an update panel. The form has multiple 'sections', each of which the user submits when completed. Each control performs a postback. This is because if the user modifies a section after completing it, the 'section saved' label needs to disappear.
This all works well, except the postbacks lose the tab order of the controls. I have found code examples that save the last control that had focus, which works well for the radio button lists, but because the text boxes post back when a user tabs to the next control (not modifies the text), it doesn't select the next control. The user has to hit tab again and it jumps to the third text box, not the second because technically, the second text box is what had focus after the initial postback. I hope this makes sense.
Any ideas? I can post code if required.
I should probably also add that this page is within a frame of our community portal.
I've got a number of RadGrids in various pages but on one of them, a particularly big one, now when the user changes the Page Size via the Pager text field it doesn't keep that: when the grid finishes updating it's reset the Page Size back to whatever it was. If I change the PagerStyle.Mode so there's a dropdown shown instead of a text field then they can change it just fine. I can change it back & forth between NextPrevNumericAndAdvanced and NextPrevAndNumeric, and consistently it works with a dropdown (NextPrevAndNumeric) but not with a text field (NextPrevNumericAndAdvanced). If I modify the Page Size with the pager shown as a dropdown, then change the aspx to use a text field, then it locks the Page Size at whatever I selected in the dropdown.
What could it be that is causing this?
Turns out the if (!Page.IsPostBack) ... had been removed from Page_Load, so on every postback it was resetting things. Putting this back resolved the problem.
Page A has a dropdownlist of shipping methods.
User makes a selection and clicks next.
Page B allows them to change their shipping address, which changes their shipping methods.
User clicks back button.
Page A shows new shipping methods in drop down, but Chrome has added a blank option at the top and made it the selected option. This blank option DOES NOT EXIST in the view source.
Chrome is choosing to insert a phantom blank selection item when its persisted drop down list value no longer exists, rather than respecting the selected="selected" tagged option.
This causes .net event validation to fail whenever the user tries to interact with the form, because this blank selection isn't real. "Invalid postback or callback argument. Event validation is enabled"
I've tried form.reset() on page load, and turning autocomplete off on the form tag. Anyone have any ideas? Much appreciated.
I have a Ajax modal popup that displays a set of options for the user. On submit button click event on the ajax modal popup, i need to pass the user selected data back to a text box on the user control (which has the modal pop up) on the calling page.
Structure/flow is as follows. There is a page and two user controls. One is a search control that has another user control that contains the user options. The master page has the search user control. When the user chooses an option in a dropdownlist in the search control, it does a mpe.Show of the user control with options. User makes his selections and hit submit button. In the button click event in the popup, i delegate an event back to the search user control which tries to set the value in one of its text boxes. Everything is going fine until this step and i can see the value but the text box never changes. It seems like the user control is already rendered and the changes are ignored. Any idea how I can get around this?
In short, how to get back the data to a control from an Ajax modal popup.
Use jquery - when the user clicks a button on the modal - use jquery to set the value field to be the data that the user has selected.
e.g.
$('#modalButton').click(function() {
var userData = $('#tbUserData').val();
$('#textBoxElsewhere').val(userData);
});
for anybody's future reference, i did a work around for this. What was happening is that, on the final button click postback, the page/parent user control load events run first and then the button click event.. so the changes that were being made in the button click event did not make it back to the parent user control on the page.. i had to add a middle step to display the user selections for approval and force the user to hit a final confirmation hit. On that post back, the changes were already available for the parent user control, and not have to wait for the button click event to trigger to grab the data. I'm sure there is a better way to do this but this is what I could come up with.