Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
button_click()
{
  if(condition== true)
  {
   popup a msg with OK and cancel
   if(user click 'ok')
   {
     then some code...;
   }
  else 
   {
      exit;
   }
  }
}
Posted 19-Oct-11 22:55pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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 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
    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
  Permalink  
v2
Comments
Amod Kumar Jaiswal at 31-Oct-11 5:13am
   
Murali krishna, I tried but not able to solve it, Please tell me in details.
Muralikrishna8811 at 31-Oct-11 5:15am
   
Are you using Jquery
Muralikrishna8811 at 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 at 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 at 31-Oct-11 5:35am
   
please help me out this.
Muralikrishna8811 at 31-Oct-11 5:36am
   
yeah sure I'm doing it
Muralikrishna8811 at 31-Oct-11 5:48am
   
hi I updated solution check it once
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check the below code.
<asp:button id="btn" runat="server" OnClientClick="javascript:return confirm('Are you sure?')" />
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

it is showing always when i m clicking on button.i dont want like this, pls read my msg what i want to populate.
  Permalink  
Comments
Tadit Dash at 23-Feb-13 2:21am
   
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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Hii professional
 
this is a java script code that may help you paste it on asp source page...
 
<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...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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);
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 Dnyaneshwar@Pune 500
2 ravikhoda 325
3 OriginalGriff 277
4 Damith Weerasinghe 265
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,777
2 Peter Leow 4,785
3 Abhinav S 3,813
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid