Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1481
  • Last Modified:

how to dialog box in asp.net

hi,

1)i have a button in aspx page and if this button is clicked i made a confirm box pop up and ask a question and if user clicks OK then i make a check (I make a sql query if this name i pass exists in some tables)

2)after that if this record exists in the table i need another warning with confirm box and user again clicks OK then i will continue with operation in the code behind to delete that record.if user click Cancel than do nothing...

Above i managed to accomplish 1st part but 2nd part i could not do??

How can I do the second part ? ...

button is inside a repeater i did the first part with Repeater1_ItemCommand and Repeater1_ItemDataBound event as below code !!

In the below code when user hits OK i query db in code behind if record exists i should warn user again but how should i do the second warning since i used the button's onclick once?


Thx for your help !!!

-----------------------------------------------------------------------------------------
 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Button btnDelete = e.Item.FindControl("btnDelete") as Button;
            btnDelete.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete:-" + btnDelete.CommandArgument.ToString() + "');");
        }
    }


------------------------------------------------------------------------------------------------------------------------
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            string hasta_adi = e.CommandArgument.ToString();
            
            // Write code to delete data from SQL
            // if this patient will be deleted what should be done is 
            //\\//\\//\\//\\//\\//\\//\\\//\\/\\/\\/\/\/\/\/
            
            
            bool i = checkpatientexists(hasta_adi);


            //if i is true that means operations exist with this patient ,warn the user again 
            //if user confirms again then proceed with deletion. !!!

         if (i == true)
         {

           // I need the 2nd dialog box here
           // but how, since there is no button or smthg?
         }
}
}

Open in new window

0
nicedone
Asked:
nicedone
  • 2
1 Solution
 
MlandaTCommented:
It would be easier to include a flag in the repeater that indicates whether a patient exists. That way, your check is done right from the onset (when you initially load the repear the very first time) and you present the appropriate prompt to the user... as opposed to only doing your second check at a later point. Web applications do not perform very well with this kind of logic.

Alternatively, modify the code so that most of your logic is handled client side. So the code which does the first check (i.e. the return confirm('Are you sure you want to delete: ) rather becomes a JavaScript function (say CheckDelete) which does two things...
function CheckDelete

   //1st asynchronously calls a PageMethod to checks if there are patient records
   //See this for help: [url="http://weblogs.asp.net/jalpeshpvadgama/archive/2011/12/24/page-methods-in-asp-net.aspx"]PageMethods Example 1[/url], [url="http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx"]PageMethods Example 2[/url]
   // store the result in a variable

  //2nd display the appropriate confirm message here and return the user's choice

end

Open in new window

Something along those lines. The reference articles might help.
0
 
nicedoneAuthor Commented:
Dear MlandaT

Thanks for the articles i checked them out...

and i can do what you say but in part

//2nd display the appropriate confirm message here and return the  the user's choice

on that part, i will not show a message actually if the user clicks OK button to that confirm box, i need to again go to code behind and delete that record if he hits Cancel then nothing will happen !!!!

how will i go 2nd time to code behind since I already used button's on click at the first one, now the scenerio is instead of clicking the button if the user hits OK to 2nd Confirm box i will delete that record from database

then i thought may be i can make a second webmethod to delete that particular record,but then in javascript i will need to pass the name of the patient as a parameter to be able to delete it right? would that work do you think? in javascript can i pass a parameter to the webmethod?

tnx..
0
 
MlandaTCommented:
how will i go 2nd time to code behind since I already used button's on click at the first one
Thats not a problem. Remember how a button works... in the onlcick event for the button we are calling onclick="return DeleteCheck('some parameters');". Now, the thing that determines whether this click causes a postback or not is actually whether the DeleteCheck function returns true or false. A return value of true causes the button to submit the form. It does not matter how complex the code in the javascript DeleteCheck method is. It could call many many PageMethods, display a thousand 'confirm' dialogs, or whatever... but what matters is the end result of all that i.e. does DeleteCheck return true or false. So you can put all your logic in this button click. In your server side code, the click handler for the button will do the delete for you.

your second approach will also work... in javascript can i pass a parameter to the webmethod?
this is possible. you just pass parameters as you normally would. so if server side code has parameters, in javascript you can pass the same parameters on the PageMethod too.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now