Making a Database entry from a dynamic modal/button.

Last post 11-10-2009 3:06 PM by Villanite. 1 replies.

Sort Posts:

  • Making a Database entry from a dynamic modal/button.

    11-10-2009, 11:49 AM
    • Member
      21 point Member
    • Villanite
    • Member since 10-16-2008, 1:58 PM
    • Posts 13

    So I have a page that has a large amount of dynamic buttons on it. The buttons are assigned to a certain item, each one is Add Child Item, Delete Item, Edit Item.

    Delete Item has been figured out by generating dynamic ModalPopup and ConfirmButton Extenders. That was simple enough.

    Unfortunately, I need to have the ability to add a child item now. This is sort of a tree of items. I want to be able to click on the Add Child Item button and bring up a modal that asks for an Item Description and Item Type. Once they click Add, the child item is added to the database and the page refreshes (since I can't, under any circumstances get the update panels to work. But that's seperate issue.)

    I have been able to get the code to work with Confirm Button and Modal Popup extenders, but the validation is ignored and if the values are not valid, nothing is entered and there is no message displayed for the user, making that solution very user un-friendly.

    What I need now is a way to be able to save the CommandArguments of my dynamic buttons to be used in the addition of the records. This way, I can click the button, bring up the modal, enter my values, and click Add Item, then the program already knows what the parent item is (because I saved its ID from the CommandArgument) and the page refreshes to show the updated changes.

    My dilema is... Is there any way to save the CommandArgument between the button click and the modal's pop up so that it can actually be used in my SQL statement?

  • Re: Making a Database entry from a dynamic modal/button.

    11-10-2009, 3:06 PM
    Answer
    • Member
      21 point Member
    • Villanite
    • Member since 10-16-2008, 1:58 PM
    • Posts 13

    Alright, I did find a solution to this, unfortunately, I don't know if it's the best solution, but it works just fine!


    Basically, my page has an "Add Root Level Item" button and then each button has an "Add Child Item" button, the child item buttons are dynamically generated.

    I do have a modal for the root level button that pops up and asks for a type and description, that's all I need, so I had my dynamic buttons just do a post back while saving a session variable. Then, on the Page_LoadComplete, I check whether or not the page is a post back, if it is, I check the value of the session. If the session variable has a value and the page is a post back, I use UpdatePanel1.Show() and the exact same adding modal pops up, my database insert function has various optional values, one of them happens to be ParentItemID, so I just make the call with a ParentItemID = Session("Variable") and ta-da!

    It's just a little bit odd... But it works!


Page 1 of 1 (2 items)