Solved

asp.net javascript message show get response and delete row

Posted on 2013-05-15
1
492 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

752 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