Textboxes not updating correctly in custom module

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
7/12/2011 5:13:04 PM
Gravatar
Total Posts 11

Textboxes not updating correctly in custom module

Hi All,

I've got a weird thing going on and not sure if I'm just losing it, or if I'm misunderstanding something about mojo. I'm developing a custom feature (module). It stores locations in a database table, and anyone with administrative rights can edit the data in the table.

I use an aspx page to view the items in a grid, and another aspx page to either add or edit data items. When editing, I simply pass the itemID as a parameter on the url. When adding a new item, I do not.

When I want to add a new item, I can enter the data into the textboxes on the add/edit page and click save, and it works perfectly.

When I am editing an existing item, I populate the textboxes on the page with the info from the database record based on the itemID that I passed. That works fine as well.

The problem happens when I am editing an existing item. I can modify the information in the textboxes and click save, but the textboxes still contain the old information.

The method that performs the save just takes the textbox.text values and puts them into the respective properties of my object which I then save. If I put a breakpoint on the method that populates the object properties and inspect the value of textbox.text, it contains the old values that I populated in the PageLoad method.

It seems like a caching or viewstate problem, but I am at a loss. I can post code if anyone thinks it would be helpful. Thanks to all.

7/13/2011 6:01:48 AM
Gravatar
Total Posts 18439

Re: Textboxes not updating correctly in custom module

Hi,

Not seeing your code I can only guess, but this is a very common mistake that people who are new to ASP.NET development make. You need to understand the lifecycle of page events. The page load event fires before any button click events on postback so if you are populating the controls with initial values in page load then the values entered by the user are lost before the button click event fires.

So the solution is to wrap any logic you have that sets the initial values like this:

if(!Page.IsPostBack) { do your logic to set initial values}

Hope that helps,

Joe

7/13/2011 7:02:11 AM
Gravatar
Total Posts 11

Re: Textboxes not updating correctly in custom module

Many thanks, Joe. I really feel like an imbecile. And actually I've been doing .net development for a long time, but in the last few months I've been doing Flash development... So now to try and come up with an excuse to protect my bruised ego I'll just say that I was really tired and I had used the codesmith template to generate the page so I put the initialize code in the PopulateLabels() method and I normally put the if (!Page.IsPostBack) in the Page_Load() method, so I just didn't catch it. Yeah, that's it. That'll work ;-)

Actually the templates are great. Thanks for the great work, and for taking the time to answer silly questions like mine.

You must sign in to post in the forums. This thread is closed to new posts.