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

Discussion in 'ASP .Net' started by seanmayhew, Apr 10, 2005.

  1. seanmayhew

    seanmayhew Guest

    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)

    private void Page_Unload(object sender, System.EventArgs e)

    #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
    //For editing and deleting fruit types.



    #region Event Handlers
    private void imgbtnDeleteFruitType_Command(object sender,
    CommandEventArgs e)

    private void imgbtnEditFruitType_Command(object sender,
    CommandEventArgs e)

    private void imgbtnAddFruitType_Click(object sender,
    System.Web.UI.ImageClickEventArgs e)

    private void imgbtnSaveFruitType_Click(object sender,
    System.Web.UI.ImageClickEventArgs e)



    Any help greatly appreciated.
    seanmayhew, Apr 10, 2005
    1. Advertisements

  2. 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 )
, Apr 10, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.