469,946 Members | 2,042 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

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

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
1 1847
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.

Similar topics

3 posts views Thread by Mike | last post: by
7 posts views Thread by Trvl Orm | last post: by
1 post views Thread by Jonathan Yong | last post: by
1 post views Thread by Karl Seguin | last post: by
6 posts views Thread by Robin Bonin | last post: by
5 posts views Thread by MS Newsgroups | last post: by
1 post views Thread by Thanks | last post: by
6 posts views Thread by John Rivers | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.