views:

736

answers:

2

Hi Friends!!

I have a Button which is having modalpopupextender which is working absolutely fine no problem at all, but before the modalpopup appears i want to validated text box control if it is not valid then modalpopup should not appear other wise it should work as usual.. does anybody having idea.

A: 

Something I've done in the past is manually show/hide the modal popup. I realize the ModalPopupExtender control requires a target, so you'll need a dummy target which will remain inactive:

<asp:LinkButton id="btnDummyTarget" runat="server" />
<asp:Button
    id="btnActualButtonTiedToValidation"
    ValidationGroup="SomeValidationGroup"
    OnClick="MyButton_Click"
    runat="server" />

<ajaxToolkit:ModalPopupExtender
    id="mpeMyPopup"
    PopupControlID="pnlSomePanelToShow"
    TargetControlID="btnDummyTarget"
    runat="server" />

Then, in your codebehind you can do the following:

protected void MyButton_Click(object sender, EventArgs e)
{
    if(Page.IsValid)
     mpeMyPopupExtender.Show();
}

This is also handy for delete confirmation dialogs.

Alexis Abril
im already assigning target control ID , and im also writing same logic in the code behind but still getting problems in the scenario mentioned above
Yaser Ahmed
+2  A: 

We use following function. On the button click you can call this function. This will validate validation group that is passed to this function and it is work will pop the modal popup otherwise validation error will appear.

function ClientSideValidate(modalId,group) 
{
   var modal = $find(modalId);

   Page_ClientValidate(group);

   if(!Page_IsValid)
   {
      modal.show();
   }
}
Fahad
With this code modal pop is not coming for the first time when the page loads.
Yaser Ahmed