Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,

I have webform with textfields & with submit button.

My requirement is after clicking submit button it should show as follows

If fields are empty it should show alertbox with certain message &

if fields contains data the if should show confirm box with yes & cancel

If ther user select yes it will redirect to another page or If the user select cancel the operation will cancel & the cursor will focus to first textbox.

How to do this?

Thanks
Posted
Comments
AshishChaudha 11-Jul-12 8:16am    
Try some thing to do with your self...if you get stuck than ask for help..its better for you only..

Nice reference is available in CodeProject article A Simple ASP.NET Server Control: Message Box & Confirmation Box[^]
 
Share this answer
 
Comments
Uday P.Singh 11-Apr-12 8:33am    
5!
varun557 15-Jul-18 8:37am    
asas
Try this, working fine
JavaScript
<script language="javascript" type="text/javascript">
function ValidateForm()
    {    
          var Form=document.getElementById('frmname');
          if(Form.txtCandidateName.value=='')
          {
              alert('Enter Name of Applicant ');
              document.getElementById('txtCandidateName').focus();
              return false;
          }
          
return true;

function ConfirmALL(btn)
     {
    
      var gr1;
      
      gr1= true;
      
      if(document.getElementById("fldGraduation"))
      {
        gr1= false;
        gr1= validationF();
      }
      
      if(!gr1)
      {
        return false;
      }
      
    
      if(confirm('Yes, I have Checked all the details.')){btn.style.display='none'; return true;}else{return false;}

     }
</script>


ASP.NET
<asp:Button ID="btnProceed" runat="server" Text="Proceed" OnClick="btnProceed_Click"                                                    OnClientClick="return ConfirmALL(this);" />



Make it answer if this is your solution, so that other can refer the solution.

Thanks
 
Share this answer
 
Response.Write("<script>alert('"+ Server.HtmlEncode(ex.Message) + "')</script>");
and
String conform = "<script>if (confirm('Are you sure you want to leave the page')){document.location='Default.aspx';}</script>";
Response.Write(conform );
 
Share this answer
 
hey,
try this
XML
<script type="text/javascript">
       function confirmation() {
            var txtValue=document.getElementById("txtValue");
             if(<pre lang="cs">txtValue<pre lang="cs">.value=="")
             {
                alert("Enter Some Data");
                return false;
              }
             else
              {
                  return  confirm("are u sure?");
              }

       }
   </script >
calling of Function
<asp:button id="btnClick" runat="server" text="Click" xmlns:asp="#unknown">
        OnClientClick="return confirmation();" onclick="btnClick_Click"/></asp:button>

Hope it will help u 
best Luck
 
Share this answer
 
Hi ,
Well you can user javascript code
JavaScript
<script type="text/javascript">
       function confirmation() {
           if (confirm('are you sure you want to delete ?')) {
           return true;
           }else{
           return false;
           }
       }
   </script>


ASP.NET
<asp:button id="Button1" runat="server" text="Button" xmlns:asp="#unknown">
        OnClientClick="return confirmation();" onclick="Button1_Click"/></asp:button>


Or you can use ajax ModalPopup you will find all information u want here

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx[^]
Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Darpan Dahal 18-Mar-13 10:07am    
thanx working nice
Mohamed Mitwalli 18-Mar-13 14:59pm    
your welcome
HTML Code

ASP.NET
<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
        <input type="button" value="Show" onclick="checkValidation();" />


JAVASCRIPT CODE
JavaScript
function checkValidation()
        {
            var textValue = $('input[id$=TextBox1]').val();

            if (textValue != "")
            {
                if (confirm('Are you sure you want to redirect Page?'))
                {
                    window.location = 'About.aspx';//link to redirect page
                }
                else
                {
                    $('input[id$=TextBox1]').focus(); 
                    return false;
                }
            }
            else
            {
                alert('TextBox is Empty');
             }

        }
 
Share this answer
 
 
Share this answer
 
hi shiva

this is for conform box

C#
String csScriptText = "if (confirm('Are you sure you want to leave the page')){document.location='Default.aspx';}";


this is for alert box

HTML
Response.Write("<script>alert('"+ Server.HtmlEncode(ex.Message) +"')</script>");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900