Need help with order of page events and adding dynamic button controls.

S

seanmayhew

I have a form page that that while editing saves the data to an xml doc
before submitting to db. On each page

unload it saves the xmldoc as the user can add multiple items to the
company like product types etc. So for

instance Im adding a fruit company while adding a fruit company I allow
the user to add types of fruit they

carry and display it dynamically using an <asp:table> with image
buttons for editing and deleteing individual

fruit types. After giving the company a name etc and adding fruit types
I submit the xml doc to the db. What Im

having problems with is the order in which things happen when trying to
add fruit types. Since the event

handler for the add fruit type button happens after page load the table
is not populated on post back but

rather on the second post back (adding another fruit type) which then
only displays the first fruit. If you add a third fruit type the page
posts back and displays the first two but not the third and so on. If I
try to

move the fruits table population to the page unload my event handlers
for editing or deleting a fruit type quit working.

here is a quick example



namespace myspace
{

public class myClass : System.Web.UI.Page
{




#region Page Events
private void Page_Load(object sender, System.EventArgs e)
{
GetCompanyInfo();
ShowFruitTypes();
}


private void Page_Unload(object sender, System.EventArgs e)
{
SaveCompanyInfo();
}
#endregion


#region Methods


public void GetCompanyInfo()
{
//Get Company Info from XML
//If company doesnt exist create a new one
//Happens every page load
}

private void SaveCompanyInfo()
{
//Save Company Info to XML
//Happens on page unload
}



public void ShowFruitTypes()
{
//Add Fruit types from XML into <ASP:TABLE>
//Provide Image Buttons with Event Handlers attached to Command
Arguments
//For editing and deleting fruit types.

}

#endregion



#region Event Handlers
private void imgbtnDeleteFruitType_Command(object sender,
CommandEventArgs e)
{//DELETE FRUIT TYPE CODE HERE}

private void imgbtnEditFruitType_Command(object sender,
CommandEventArgs e)
{//EDIT FRUIT TYPE CODE HERE}


private void imgbtnAddFruitType_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{//ADD FRUIT TYPE CODE HERE}

private void imgbtnSaveFruitType_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{//SAVE FRUIT TYPE HERE}


#endregion




}
}


Any help greatly appreciated.
 
N

newsgroups.comcast.net

You've answered the question your self. You need to move the 'Displaying
Fruit types' logic to the Add Image button handler. In Page load, just
display the fruit type for the first time ( while !Ispostback )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top