Saturday, March 24, 2012

Conditional Modal popup?

I have a <asp:checkbox> control on my ASP.NET page as a column (template item) in a GridView. This check box is to mark certain thing as reviewed. When the user checks it, before I run my sql query to mark the sql table rows as reviewed, I would like to pop up a confirmation dialog to the user.

However, this confirmation is not always needed, based on a condition (i.e.) if the GridView row that this check box is on is currently highlighted i.e. selected, then I don't need a confirmation. But if some other GridView row was selected and the check box on some other row is checked then I would like to confirm with the user.

I checked the modalpopup in Ajax toolkit, but it seems like it pops up every time the target control is clicked. I need the ability to be able to decide when to show the popup and when not to.

Please help.

instead of assigning the modal popup to a target control. Assign the target control id to a hidden field, so just make a random hidden field on your form with the id modalTarget and set the popupcontrolid for the modal to be modalTarget. Now you have it set up so nothing can cause the modal to popup since users cant really interect with the hidden field. You are now free to use the Show() function to display the modal popup. So say you click the submit button and first want to check if the checkbox is clicked. all you have to do if it is checked is something like this

if(checkbox.Checked == true)
{
modalPopup1.Show();
}

modalPopup1.Show(); will allow you to show the popup any time u want :)


Thanks for the neat idea. One question though, after the popup shows, how would I check if the ok was selected or the cancel?

ex:

if (selectedRowIndex != checkBoxRowIndex)

{

modalpopup1.Show();

}

// check if the Ok button was clicked (how to check that??)

if yes

call UpdateSQLRows();

else // cancel button clicked

do nothing.


i have never used these but you might wanna try setting the okControlID so you can use that to determine what the user clicked. or just write onClick events for your buttons

OkControlID - The ID of the element that dismisses the modal popupOnOkScript - Script to run when the modal popup is dismissed with the OkControlIDOkCancelID - The ID of the element that cancels the modal popupOkCancelScript - Script to run when the modal popup is dismissed with the CancelControlID

Thanks, I will work on that.

No comments:

Post a Comment