ASP.NET - how to pop up option of yes/no button in asp.net

Asked By aman on 29-Dec-11 01:21 AM
hello,

i want to do textbox validation using javascript ,that i known how to do it....but my concern here is that i want to pop up a dialog box which will provide yes/no option and based on the user input i want to further continue with the validation process......but i dont have any idea of doing this because have never done such thing using javascript validation in asp.net

i hope that i have make question clear.........(pop up dialog box with yes and No option as we can do in Windows Application).

please help me...

thanks,
regards,
Aman Khan
Web Star replied to aman on 29-Dec-11 01:25 AM
Use confirm messagebox to show 'yes/no' option in that popup, and do different work based on click either yes or no.
eg
protected void Button1_Click(object sender, EventArgs e)
   
{
       
ClientScriptManager CSM = Page.ClientScript;
       
if (!ReturnValue())
       
{
           
string strconfirm = "<script>if(!window.confirm('Are you sure?')){window.location.href='Default.aspx'}</script>";
            CSM
.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
       
}
   
}
   
bool ReturnValue()
   
{
       
return false;
   
}
Suchit shah replied to aman on 29-Dec-11 01:29 AM

You can store the value of confirm_proceed() in an asp:HiddenField

You can modify your script as follows:

<script type = "text/javascript" language = "javascript">
function confirm_proceed()
{
var hiddenField = document.getElementById('hiddenFieldId');
if (confirm("Are you sure you want to proceed?")==true)
{
hiddenField.value = 'true';
return true;
}
else
{
hiddenField.value = 'false';
return false;
}
}
</script>

You can now access first the hidden field's value in your Button2_Click event.

or try this simple



Button2.Attributes.Add("onclick", "return confirm('Are you sure you want to proceed?')");
Suchit shah replied to aman on 29-Dec-11 01:34 AM
you can also do it like below one

<table width="100%">
            <tr>
              <td>
                <ajaxToolkit:ModalPopupExtender ID="modalConfirmDelete" runat="server" PopupControlID="pnlDelete"
                  Drag="true" DropShadow="false" BackgroundCssClass="modalBackground" PopupDragHandleControlID="pnlApprove"
                  TargetControlID="HiddenButton" CancelControlID="btnClose1">
                </ajaxToolkit:ModalPopupExtender>
                <asp:Panel Style="display: none" ID="pnlDelete" runat="server" Width="40%" CssClass="modalBox">
                  <asp:Panel Style="cursor: hand" CssClass="ModalCaption" ID="pnlApprove" runat="server">
                    <table width="100%">
                      <tr>
                        <td class="textmodal">
                          <asp:Label ID="lblAction" runat="server" Text="Are you sure you want to delete the document?"> </asp:Label>
                        </td>
                      </tr>
                    </table>
                  </asp:Panel>
                  <table width="100%">
                    <tr>
                      <td align="center">
                        <asp:Button ID="btnYes" runat="server" CssClass="button" OnClick="btnYes_Click" Text="Yes"
                          Width="57px" />
                        <asp:Button ID="btnNO" runat="server" CssClass="button" Text="NO" />
                      </td>
                    </tr>
                  </table>
                </asp:Panel>
              </td>
            </tr>
          </table>
smr replied to aman on 29-Dec-11 02:04 AM
hi

For true Javascript standard it is not possible. This will only work on 32 bit Windows and only on IE. On Firefox it will not show Yes/No prompt.

<script language="javascript">
  function window.confirm(str)
  {
    execScript('n = msgbox("'+str+'","4132")', "vbscript");
    return(n == 6);
  }
  var r = confirm("Can you do it?");
  alert(r);
</script>
dipa ahuja replied to aman on 29-Dec-11 02:31 AM
Either you can use the modalpopup or you can use confirm box

Web app:

<asp:Button ID="Button4" runat="server" Text="Confirm"

onclick="Button4_Click" />

protected void Page_Load(object sender, EventArgs e)

{

    Button4.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to add new record?')");

}

protected void Button4_Click(object sender, EventArgs e)

{

    //code if click yes

}

<
cc1:ModalPopupExtender TargetControlID="Button3" BackgroundCssClass="modalBackground"
PopupControlID="Panel1" CancelControlID="LinkButton4" PopupDragHandleControlID="btnMsg"
ID="ModalPopupExtender1" runat="server" />
  
<asp:Button ID="Button3" runat="server" Text="Take Input" />
 
<asp:Panel ID="Panel1" runat="server" Height="80" CssClass="ModalWindow">
<%--Take textboxes here--%>
<asp:LinkButton ID="LinkButton4" runat="server" Text="X" />
Records updated
</asp:Panel>
 
 
Jitendra Faye replied to aman on 29-Dec-11 03:32 AM

If you want to show modal popup then use jquery popup.

after adding jqueryui plugin you can use it.

like this-

<script>

function funShow() {

$('#dialog).dialog({ resizable: false, height: 140, modal: true });

}
</script>

<div id="dialog" title="Basic dialog">hi
</div>


<asp:Button runat="server" Text="Button" onClientClick="return funShow()" />

Note- This will be closed when you will click on close button,

FOR EXAMPLE FOLLOW THIS

-http://jqueryui.com/demos/dialog/