Monday, March 26, 2012

Modal Popup OnOkScript to call CS code.

Hi,

This is a pretty basic question but i haven't been able to find an answer for it anywhere. I have read on how to show a modal popup from a cs event handler but what i need to do after the popup ok is clicked is to go to a nother event handler or even a public function on my cs file.

Here is a simple explanation of the problem i have. Say i have a gridview with data and i want a button to delete a row. I want that to show my modal and the ok to call a function on my cs file with the row it was on so that i know which row in my gridview to delete.

Is this possible to do with the ModalPopUp?

Thanks,

Kambiz

there are 2 things you can try.

1. set theOkControlIDto a button that is hidden ( hidden using the style tag not the visible tag) and then use the ok button as a normal asp:button and define the click event. Inside that click event, delete your gridview row, and then modalpopup1.close().

2. is to use theOnOkScript to call a javascript function which does a callback to a webservice function to delete the row.

The first way is how I have done it, and it works fine.


There is one other option that I found while searching through the forums...

In the <asp:Button> for the OkButton, assign the UseSubmitBehavior to False. From what I have found this overrides the javascript response and will let you get to the button event from the OkButton.

ex: When the OkButton is pressed it goes directly to the OkButton_Click event handler in the code behind file, from there you can do whatever actions are required.

<asp:ButtonID="OkButton"runat="server"Text="OK"UseSubmitBehavior="false"OnClick="OkButton_Click"/>


Thanks for the help. I got that to work.

Here is the problem i have now. I want to have my button in a grid view so i have records in a grid view with say a delete button. How can i have the TargetControlID be a range of ID's? This way i'd have many targetid's trigger the modal and have that allow the user to confirm that they want to delete the row. I'd really appreciate any input on how to accomplish this.

Thanks,

Kambiz


you can't have a range of triggers, but there are a few ways of doing it. The best is to use the dynamic content aproach delay blogged about

http://blogs.msdn.com/delay/archive/2006/11/30/dynamic-content-made-easy-remix-how-to-use-the-new-dynamic-population-support-for-toolkit-controls.aspx

Another way, is if you just hide the button that is associated to the TargetControlID and then in the event hander for the button in the gridview just call the modalpopup1.Show() method.

Let me know this helps


Hi aquillin,

That makes perfect sense and yup it works perfectly. This way i can actually dynamically fill the message within the panel letting the user know which row they are going to be deleting.

Thanks for your quick answer and great assistance.

Kambiz


Hi aquillin,

I was just able to check the way you recommended which was to hide the button associated with the TargetControlID and just call the show method from the gridview. Unfortunately it doesn't seem to work when the button associated with the TargetControlID has the property visible=false. When i change the visible back to true it works fine. Any ideas on another work around?

Thanks,

Kambiz


I actually just answered my own question. I set the linkbutton to have a cssclass with a display:none and that makes it work just fine.

Thanks

Kambiz


use style instead of set visible = false.

for example: <asp:Button ID="btnInvisible" runat="server" style="display:none" />


The easiest way to accomplish this is to not set the OkControlID property in your ModalPopupExtender. This will let the postback occur and your event will be fired correctly. You should then be able to hide the popup using the Modalpopup.Hide() method.

On the same note, if anybody knows a way for the event to fire and the OnOkScript to execute it would help me out a lot.

Hope that helps,

Searlzy


1. I want to reload the contents of popup, every time I use ModalPopup.Show() in my event.

2. Is there a way to clear the popup. (Apart from ModalPopup.Hide())

No comments:

Post a Comment