views:

9739

answers:

3

Hello.

I want to show a modal popup when a user click on an asp button. The user must select an option of a panel. The value of the option selected must be saved to an input hidden and then the asp.net button must do a PostBack.

Can I do that?

Thank you!

+1  A: 

Add your Button or LinkButton

<asp:Button ID="MyButton" Text="Click Here" runat="server" />

Add a Panel to hold your options with a DropDownList

<asp:Panel ID="MyPanel" runat="server">
  <asp:DropDownList ID="MyDropDown" runat="server">
    <asp:ListItem Value="1" Text="Option 1" />
  </asp:DropDownList>
  <asp:Button ID="SaveBtn" Text="Save" OnClick="Save_Click" runat="server" />
  <asp:Button ID="CancelBtn" Text="Cancel" runat="server" />
</asp:Panel>

Add your ModelPopupExtender

<act:ModalPopupExtender ID="Mpe1" TargetControlID="MyButton"  
 CancelControlID="CancelBtn" PopupControlID="MyPanel" runat="server" />

Then add your code behind to the SaveBtn Button

public void SaveBtn_Click(object sender, EventArgs e) {
  string selectedOption = MyDropDown.SelectedValue;
}
David G
Yes, it's a great solution but when it shows the modal popup it doesn't go to server.
VansFannel
+3  A: 

It is possible for a ModalPopupExtender to be displayed using a postback. You'll need an invisible target control. The extender is attached to this hidden control.

<asp:Button runat="server" ID="btnShowModal" Text="Show" 
     OnClick="btnShowModal_Click" /> 
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolKit:ModalPopupExtener ID="Modal1" runat="server" 
     TargetControlID="HiddenForModal" PopupControlID="PopupPanel" />

In your message handler in code-behind, you'll show the ModalPopupExtender:

Modal1.Show();

And in the code you're using to dismiss the Modal, call the ModalPopupExtender's Hide function:

Modal1.Hide();

I use this method for showing a modal that displays detailed data that I retrieve from a database based on what's selected in a GridView.

Tim
How would this work with GridView TemplateField containing a LinkButton that is to display the modal on click? I have rows of data that I want to 'Edit' the details of when clicking the LinkButton on that row.
Mark Richman
+1  A: 

Finally, I've decided to use jQuery to show a ModalPopUp. The following question has the answer to this question:

http://stackoverflow.com/questions/2325431/jquery-uis-dialog-doesnt-work-on-asp-net

If you are not agree, tell me.

VansFannel