Solved

asp.net javascript message show get response and delete row

Posted on 2013-05-15
1
490 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

856 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