I have an updatepanel, with a bunch of things in that are generated dynamically.
Among them are textboxes, and checkboxes. Each is created in code with Textbox t = new Textbox() and Checkbox c = new Checkbox and are added withotu altering any other properties.
Later on when I hit "Save", I get the values. The Textbox value is whatever I typed in before I hit the save button, but the Checkbox is always false regardless of whether I checked it or not.
Is there any explanation for this discrepancy?
Another problem solved after hours of debugging... I fixed a problem a couple of days ago that was caused because my controls didnt have an ID when they were dynamically generated. I read somewhere that controls without IDs sometimes behave oddly...
So in this case I gave my controls (checkboxes, not the textboxes) a random GUID, but it changed every time they were redrawn, which confused the viewstate and meant it couldnt preserve the contents.
Related
I know this is a problem that's been asked a few times before, but having had a look around I can't seem to find an answer that works for me.
I have a VB.NET page with 2 textboxes (set to show dates using JQuery), a dropdownlist and a datagrid.
Both textboxes and the dropdownlist are set to fire events, if they're changed, to update the datagrid.
Generally this works fine with one exception; when I change the value of either the textboxes or the dropdownlist after the initial page loading it often doesn't fire the event, the postback is set to false and the dropdownlist value is cleared; this doesn't happen in Chrome and is less frequent in Firefox than in IE.
I've tried the following:
I've set autopostback=true on all items
Tried adding an extra item, which isn't enabled, to the dropdownlist
Moved the boxes/List outside the update panel
Set ViewStateMode=Enabled
Tried adding a hidden field which is set to Request.Form(ddlDropdownList.UniqueNumber) and comparing it to Request.Form(ddlDropdownList.UniqueNumber) in the page load as a way to fire the event (the suggestion says to use Request.Forms, but this isn't coming up as an option on intellisense?)
All of these solutions either don't work, cause other issues, or I'm not doing them right (Which could certainly be the case)
Thanks in advance for any help you can give.
I don't know if this will help, it's been a while since I've done web forms, but I do recall there being a problem with listboxes where I had to check if the page was not on a postback when populating it.
So basically in your page loading method, check to see if the page is not a postback before initalising it. I found that even though I selected a new item, it was resetting the list back to it's default state.
This may or may not help you, but I thought it was worth at least mentioning it.
I have really put in significant efforts to somehow find an answer; having failed I have then searched many forums before coming to bother the experts here. Please help!
I have a Listview in a USerControl of my main form; its InsertItemTemplate has a TextBox whose value is to be filled in by Clicking a Linkbutton in a Row of another Listview (in another UserControl) in the ModalPopUp Panel, which Pops up when a Linkbutton in the Parent UserControl is Clicked. After the selection (by clicking the LinkButton in the ModalPopUp), the ModalPopup closes immediately and in Code-Behind of the Child-UserControl, I save the Selected-Value in a Session variable. My problem is (Because the InsertItemTemplate is already remaining displayed) I do not know where to put the code for filling the TextBox (in the Parent UserControl) with the saved value from the Session-Variable.
ItemCreated, ItemDataBound are already executed before the ModalPopUp is displayed. So, though I have the required Value of the TextBox in the Session-Variable, I am unable to fill the TextBox in the InsertItemTemplate.
I will appreciate any suggestions, if any of you have found any answers to such a situation. I feel SOMEHOW the InsertItemTemplate should be made to load again and this TextBox in it should be filled in the ItemCreated for the InserItem datatype. But I do not know how to make it happen???
Any thoughts welcome. I have similar logic in many places in my App; and if I can't do it it will significantly affect my app :-(.
Hope one of you experts will kindly help me out. Thanks.
Thanks. I could fix it. Mentioning it here for some newbie (like me) who may face a similar issue.
The question was, where to put the Code (for the Selected Value to fill the TextBox in the InsertItemTemplate) in the scenario described above in the question.
I find that in the Pre-Render Event of the Parent UserControl, in the PostBack mode, after finding the said TextBox Control via the e.InsertItem.FindControl("TextBox"), I am able to fill it with the selected value. I don't know if this is the best way to do it, but it works fine now.
Hope this may be of some help to someone! Thanks.
I'm generating a listview with textboxes inside. The textboxes values comes from a database. My issue comes when I want to retrieve the new values of the textboxes.
Here's what I do on click of the save button.
For Each item In mylistview.Items
Dim tbLgName As TextBox = CType(item.FindControl("tbLgName"), TextBox)
// code to encode into db ...
Next
The thing is it get the textbox but with the old values (coming from the db), How can I get the new value?
Thanx
I had this same issue and found that it was because I had added an OnLoad to my UpdatePanel that was binding this ListView. It was easy to fix because I was not using that way anymore and just removed it. For others it may not be as easy to fix, but may help figure out what is causing it.
(Yes, I realize how old this post is, but someone else may benefit down the road)
This project has gone from being a simple '99 Ford F-150 to the Homer.
I've got controls with a gridview with textboxes for data entry.
All the user controls on the pages are in AJAX updatepanels.
User types in a database column or budget entity or some other financial thing they want to include in the report.
The textboxes in the gridview have autopostback = true set.
overly long background info
When the user leaves the textbox, during the postback (triggered by onTextChanged) I do some validation back on the server on their entry - regexs, do they have rights to that column, is that column locked, etc. If it fails, I put a error message next to the textbox. If it passes, I wipe out any title or error that used to be next to the code.
Focus is getting lost from the postback if they're tabbing out of the box, rather than going to the next textbox in the gridview.
So to fix that I need, if their leaving the tb via the tab key, to also figure out what textbox or gridviewrow they're on, if they're not on the last row, and after the validation and labeling, put the focus on the textbox in the next row.
I can't figure out how, in ontextchanged, to find what caused me to leave the textbox, so I'm thinking use javascript onkeyup to test the key pressed and then find the next box etc, but the ontextchanged fires first and then the js never does, and also, since the control is all AJAXed, the javascript can't find the textboxes because when you enter the page everything is collapsed (the requirements people loooove to collapse and expand things), and so when it's expanded, all the 'new' textboxes are up in the viewstate stuff in the page source, and not down where javascript can see them.
The questions
So I'm wondering if I can have an onblur in the javascript that can trigger a postback where I can do my validation and such, and either 1) include the keypressed or pick it out of sender in the event or 2) followup the onblur with onkeyup and somehow figure out what textbox is next on the grid and throw focus there.
Or, is there another .NET based approach that could work for this? In terms of tearing the whole thing down and starting from scratch, I couldn't sell that to the bosses, I'm past the point of no return as far as that goes.
Does changing the one textbox value change anything else on the screen besides the error message/title associated with the textbox?
If not, my first thought would be to stop using the AutoPostBack and change to a Page Method hooked up to the onblur event. This should fix your tab issue and also reduce the back and forth between client and server.
Here's a blog post that talks about update panels and also Page Methods; The blog also includes a lot of useful posts about using javascript with .net, ajax, etc.
I have an ASP.NET page using the AJAX library. There is a dropdownlist inside an UpdatePanel, which on index changing is supposed to update a different UpdatePanel to modify a grid control.
But after the page first comes up, and you adjust the ddl, the entire page postbacks, followed by a (correct) partial postback. After this one time, every other usage of the ddl performs correctly, trigger partial postbacks.
Both the panel and the ddl are being added from code. The UP is Conditional updates and ChildrenAsTriggers = true. The dropdownlist is AutoPostBack true and has an event set up on SelectedIndexChanged.
So what is going on? I've tried adjusting every setting I can think of and still the page completely refreshes once, then works fine after that.
I believe I've solved my current woes in regards to this problem, though I'm left feeling a bit dumb by the outcome. When programmatically adding the dropdownlist, I didn't give it an ID, assuming ASP.NET would just assign it some sequential name-container mangled ID anyway. It seems this was the cause. I'm assuming that the initial postback was due to ASP.NET trying to deal with the lack of a proper ID, assigning one, and then using that afterwards for the partial postbacks.
Or maybe it's something totally different at root, but the simple fix was: add an ID to the control.