My problem is that all the textbox's my formview are getting cleared when I hit the submit button.
I currently have a page with a small section that has an update panel around it. This small section adds an address to my databse. To the left of this form there is a gridview that is tied into the formview. So if i click on an item in the gridview its contents fill the address section(formview) with the correct data.
When I hit add the data gets validated in the c# code behind, and if all the info is correct the address is inserted. If there is an error the entire form is cleared and the error message(label) is displayed.
I have already done this many times in other pages, but none have had the gridview tied to the formview, and they have all worked. I tried removing the gridview and the form still erases itself.
Is there some reason that .net thinks it should be clearing the form? When in other cases it decides it won't? If so what are these cases, or what general tips should I try to solve this?
in the page_load are you using if(!Page.IsPostback) { ... } so if it's a postback nothing gets re-bound?
is the ViewState enabled?
Yup many hours later I found that a single panel that was wrapped around the section had a EnableViewState="false" added to it. Sad part is that I know I didn't add that because I didn't even know what it was until craig here mentioned it. Visual Studio must have added it sometime.
Related
I'm facing a problem with one of my pages. I have a FormView control on the page that I use to enter new rows into a database table, and a GridView control on the same page to update/delete rows from the same database table.
The FormView control has validators on it to validate any input being thrown at the database, and it seems to interfere with the GridView when I try to edit a row. When I try to save the edit, the validation control on the FormView gets fired and an error comes up because the textbox input is blank, so the GridView cannot save the modified table data.
Perhaps a visible example will help:
I had an idea where I encase these controls in different forms, hoping that the submit of one form won't fire anything in the other but then I got an error saying I can't have more than one form on the page with runat="server", which as far as I can tell is required.
How can I get around this?
Thanks.
You can only have one Form.
Use different ValidationGroups for your FormView and GridView instead.
http://msdn.microsoft.com/en-us/library/ms227424(v=vs.100).aspx
Yes, this is a known limitation (feature?) of webforms. You can only have 1 form with a runat="server" tag.
In your scenario you can use ValidationGroup names to group validation together so only "like" validation is executed when a control of the same validation is triggered.
What I did is I had two forms coded as postback to the page and parsed out the postback variables in Page.Load myself. Weird? Yes. Works? Yes.
I have got this event in my page aspx.cs:
public void deleteBtn_Click(object sender, CommandEventArgs e)
{
UsefulStaticMethods.DeleteComment(int.Parse(e.CommandName));
}
I am trying to delete a comment from the page. The deletion is successful. However, the website interface doesnt update itself after that event happens.
My Page Load is responsible to drawing all the comments on the page with a dynamic button (delete comment).
I know when the delete button fires, the page Load fires before.. and thats a bit is a problem..cause the page load recreates the page interface, while the deleteBtn_click deletes the comment, and I want to update the interface straight away... "Refresh" the page without the comment that was deleted..
If i execute a function to draw the whole table again, it will draw another comment list along with the comment list drawn at the page Load event.
I cant not refuse not to draw the comment list at page_load, cause i need everything recreated at postback time (including the dynamically created button).-cant use !Ispostback
The question is how can i achieve this/overcome the issue?
Typically, if your using data-binding then you can just re-bind the control in question. Perhaps, you should modify your function that draws the comment list to clear the existing list (possible by removing rows from table control or clearing control collection from container panel or placeholder (you can introduce a placeholder control just for clearing purpose)).
Yet another hack to refresh the page is to restart the page-life cycle by doing Server.Transfer to the same page. Generally, I wouldn't recommend this approach unless page code structure is very complicated and refreshing the data would take many lines of code.
You need to rebind control. Suppose your button is in Grid than you need to Rebind() grid. If not than there is one more way. Put Contents in Update panel and set Update panel Trigger with Delete button. SO when Delete button is clicked that update panel cause Update.
Use data list or repeater server control to display comments and than bind the server control again after deletion. Use !Ispostback on Page_Load.
Yes, I realize that's a bit of a vague title but I'm having a hard time stating the problem. I have a .Net .aspx page that has a Master page, some Ajax, and an updatepanel. My problem occurs on 2 different pages but in both cases I'm either selecting a radio button or a checkbox when the behavior occurs. Immediately after selection the entire page moves down. It does not scroll but instead it is like an extra tag was inserted into the source. I have done HTML source comparisons before and after this change and nothing is different. I can only assume it is related to the updatepanel but I cannot determine where this may be happening.
I'd be happy to provide more information if you can direct me towards a solution.
Thanks!
I am not entirely sure if this will do it and there is not enough detail here to be sure, but have you tried setting RenderMode to inline on the UpdatePanel? Maybe that will do the trick. Otherwise go take a look at Fiddler and see what is coming back from the server. Alternate recommendation (if none of the above work) is to just get your result in Json and change the markup yourself with jQuery or something like it.
Incredible. This was exactly the problem. I've modified my code as follows and form stays in place after selection. This was a simple case of selecting a radio button and having it auto-populate a dropdownlist.
[asp:UpdatePanel ID="panelValidation" runat="server" ChildrenAsTriggers="true" UpdateMode="Always" RenderMode="Inline"]
[ContentTemplate]
[asp:ValidationSummary ID="ValidationSummary1" runat="server"]
[ContentTemplate]
[asp:UpdatePanel]
Thanks!
I know there is a similar problem on this forum, but the solutions did not really work for me. I am populating form controls with fields from a few different data sources, and the data shows up great.
I have an ImageButton control, which has an OnClick Event set to grab all of the data from the form. Unfortunately, when I click the button, it seems as though the page is reloading first, and THEN is executes the OnClick call. The data that was hand-entered, or hard-coded seems to be pulled fine from the controls it was entered in, but anything that was pulled from a datasource is not able to be read. Any ideas. this is the last hurdle in a project that I have been working on for 6 months.
Are you talking about drop downs or gridviews? When are you binding data, on page load?
Good design will have you bind your data upon page load but only in
if(!isPostBack){
dropdown.databind()
gridview.databind()
}.
Otherwise it will rebind every page load. If its not reloading you can get selected values from those controls if thats what your looking for.
An alternative is to set your data source and databind in your aspx page with a datasource object. That automates the above automatically.
Have you enabled viewstate on your controls? Posting code samples would go a long way to helping solve your issue.
When you click on a bottom in asp.net at first all the page Events take place like Page_Load and ... and then the event happens ( in this case Click).
But because everything is loading again, I think that you have a !isPostback in your code that you use to bind the data, you should remove that in order to get your data every time.
Or if it is not the solution please post some code and more description for the problem
Actually, it is hiddenfields, dropdowns, labels, and textfields. I just tried doing the binding in the init, and the load, but no dice. When I tried binding it on !isPostBack only, none of the fields showed up.
I think one of the main problems is that the dataset I am getting is from a method call to an API. I receive the data fine, but it comes in programmatically, then I have to do all of the control-setting programmatically as well. Would you like to see the code for ideas? Thank you for helping, no one is working today!
Jason
I am working on an .net (C#) web application.
Recently a defect came my way that stated that when two users were logged into the application at the same time they both could not update values without one refreshing the page. When I looked into the issue I discovered that the author of the code has used static datasets. I changed the datasets to not be static and everything works great.
However, This issue spans many pages in the application and I must fix it everywhere. On some of these pages the application uses datasets to bind data to datagrids. The datagrids are populated with the information in the dataset and the footer contains some textboxes and an add button to add extra rows. Here is where the problem starts:
When the page was using static datasets and the user attempted to add a row through the interface everything worked fine. However, when I changed it to use datasets that were not static (they are loaded every time the page loads) and the user attempts to add a row, the code thinks that the textbox is empty (discovered when debugging even though I can see the text that I entered) and empty field validation fails and a message is displayed.
Can someone please tell me why on Earth this is happening? Why does it see the text when the dataset is static (the dataset NEVER populates the foot row) and not see the text when it is not static? Some insight would be awesome!
Thanks in advance!
Turns out there was an issue with how the grid was binding.
The binding was occurring when the datasets were being instantiated. This means that every time the page loads the binding was occurring again and causing the text to be blank. This is weird considering the item command looked like it was executing before the page load, but the datagrid didnt like it anyway. I moved where the binding was occurring so that it only happens once when the page loads (and of course it happens when something is added to the grid).
This seemed to do the trick!