Solved

asp.net javascript message show get response and delete row

Posted on 2013-05-15
1
486 Views
Last Modified: 2013-05-28
I have an asp.net web app.

in a gridview i list some records and there is a delete asp button in each row.

when i click delete button on the page.

i pop up javascript message in GridView1_RowDataBound

since this is a click event i catch it with below line.

Button x = e.Row.FindControl("DeleteButton") as Button;
            x.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete:-" + x.CommandArgument.ToString() + "');");


But after that in the Row_Command i make a check on the patient and if operations exist on him/her (if i==true)

i want to display another pop up saying that operations exist do you still want to delete everything related with this person and according to the response i will delete or not.

What i could not achieve is ;

Since the second popup is not coming from button click or smthg i could not show the pop up,and get the user response, if user said OK then i should delete in the code behind if Cancel then do nothing.

As you can see my codes below can you help a little with the code what i should put to this code to make this work.. by the way i use MasterPage so ContentPlaceholder exists.
********************************
DESIGN
   <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting">
    <Columns>

        <asp:TemplateField HeaderText="Silinecek">
            <ItemTemplate>
                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete"  CommandArgument=<%#Eval("AD")%> Text="Delete"  />
            </ItemTemplate> 
        </asp:TemplateField>

    </Columns>
    </asp:GridView>

Open in new window

**************************************************
CODEBEHIND
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

           Button x = e.Row.FindControl("DeleteButton") as Button;
            x.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete:-" + x.CommandArgument.ToString() + "');");
                  }
    }


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
           string patient= e.CommandArgument.ToString();
           bool i = checkpatientexists(patient);

            if (i == true)'operations exist
            {
                ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
                Button y = (Button)cph.FindControl("y");

                y.Attributes.Add("onclick", "javascript:return confirm('Do you again delete?:-');");

System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=JavaScript> if(confirm(Patient has operations==>>" + e.CommandArgument.ToString() + "')==true){};</SCRIPT>");
               
            }
        }
    }

Open in new window

0
Comment
Question by:nicedone
1 Comment
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 500 total points
ID: 39186539
Hi

change java scrpit reg

ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script type='text/javascript'>" + "alert('Record deleted successfully!!!');</" + "script>");

http://www.dotnetspider.com/forum/293684-Show-alert-or-confirm-message-from-serverside-asp.net.aspx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Split in Javascript 5 30
Receiving a string from a WebService Push 21 31
form button worked now it doesnt anymore 9 36
insert text field data into html script 13 18
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now