Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
button_click()
{
  if(condition== true)
  {
   popup a msg with OK and cancel
   if(user click 'ok')
   {
     then some code...;
   }
  else 
   {
      exit;
   }
  }
}
Posted

Hi,

you can not integrate or combine two requests in single process.
my suggestion is approach jquery or asynchronous requests.to check condition on server from client using jquery thn if true in response post required data to server .to perform "then some code"


updated Answer

HTML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script language ="javascript" >
        function savefile() {
            $.post("default3.aspx?action=checkfile", { filename: document.getElementById("fileupload1").value }, function (data) {
                if (data == 'Yes') {
                    if (confirm("Are you Sure")) {
                      
                    }
                }
                else {

                }
            });
        }
    </script>
 


</head>
<body>
    <form id="form1" runat="server">

    <div id="maincontent"  runat="server" >
    <input type ="file" id="fileupload1" />
        <input type ="button" value ="Save File" id="btnsave" onclick ="savefile()" />
     
    </form>
</body>
</html>


And code behind file contains
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["action"] != null)
    {
        if(Request.QueryString ["action"].ToString()=="checkfile")
        {
            Response.Clear();

            bool execsts = true ;
            //check wheather file is exists or not
            //if exists send response to client as Yes
            if (execsts)
            {
                //send response as Yes if it exists to confirm
                Response.Write("Yes");
            }
            else
            {
                //save file if it doesn't exists
                Response.Write("File Saved Successfully");
            }


            Response.End();
        }

    }
}


This just for bring idea only

you've to modify it for your requrement.

All the Best
 
Share this answer
 
v2
Comments
Amod Kumar Jaiswal 31-Oct-11 5:13am    
Murali krishna,

I tried but not able to solve it, Please tell me in details.
Muralikrishna8811 31-Oct-11 5:15am    
Are you using Jquery
Muralikrishna8811 31-Oct-11 5:16am    
if you don't mine can you clearly post what are you going to check and after that what you to do
Amod Kumar Jaiswal 31-Oct-11 5:23am    
if (txtFileName.Text == Convert.ToString(Path.GetFileName(fileListName[i])))
{
Popup message “You want to overwrite” with [ok] [cancel]
fuFile.PostedFile.SaveAs(SaveLocation + fileName);
}


if I click ok then execute next line if I clicked cancel then just exit from conditon .
Amod Kumar Jaiswal 31-Oct-11 5:35am    
please help me out this.
Check the below code.
ASP.NET
<asp:button id="btn" runat="server" OnClientClick="javascript:return confirm('Are you sure?')" />
 
Share this answer
 
v2
 
Share this answer
 
v2
it is showing always when i m clicking on button.i dont want like this, pls read my msg what i want to populate.
 
Share this answer
 
Comments
This is a comment. So, add as a comment in the answer box you want to.
Please don't post your comment as an answer.

Thanks,
Tadit
C#
ibtnDelete.Attributes.Add("language", "javascript")
ibtnDelete.Attributes.Add("OnClick", "return confirm('Are you sure you want to delete this record?');")

This will bring up an OK/Cancel box when the button is clicked; if Cancel is then clicked the button's click event code won't run.
 
Share this answer
 
v2
Hii professional

this is a java script code that may help you paste it on asp source page...

JavaScript
<script type="text/javascript">

    document.getElementById("yourButtonId").onclick = function()
 {
 var confirmation = window.confirm("Are you sure want to?"); //confirmation variable will contain true/false.

        if(confirmation)
 { /* Write code for Yes */ }
        else
 { /* Write code for No */ }
    }
</script>


Happy to help...
 
Share this answer
 
If You want to show the alert from Page behind I mean from aspx.cs side then you can use:

protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(GetType(), "sas", "javascript:alert('success');", true);
}
 
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