By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,728 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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 )

<se********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.