Getting user input with pop up's

Last post 01-25-2007 8:36 PM by Jessica Cao - MSFT. 5 replies.

Sort Posts:

  • Getting user input with pop up's

    01-22-2007, 3:45 PM
    • Loading...
    • edpeloquin
    • Joined on 01-22-2007, 8:39 PM
    • Posts 4
    I'm currently developing an application where I have a gridview and a delete linkbutton for each row.  When the user clicks this button I want to prompt them for a reason using a pop up input box similar to the javascript confirm dialog box only with an input field instead of just ok and cancel options.  How can I accomplish this?
  • Re: Getting user input with pop up's

    01-22-2007, 10:18 PM

    hi,

    try this

    <asp:GridView ID="GridView1" runat="server" OnRowDeleted="RowDelete">
            <Columns>
            <asp:TemplateField HeaderText="Delete">
            <ItemTemplate><asp:LinkButton ID="delete" runat="server" Text="delete" CommandName="Delete" /></ItemTemplate>
            </asp:TemplateField>
            </Columns>
            </asp:GridView>
            protected void RowDelete(object sender, GridViewDeletedEventArgs e)
        {
            string script = "<script language='javascript'>window.showModalDialog('Default2.aspx');</script>";
            Page.RegisterStartupScript("JavaScript",script);

           do your delete function
               }

    Jessica Cao
    Sincerely,
    Microsoft Online Community Support


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: Getting user input with pop up's

    01-23-2007, 4:59 PM
    • Loading...
    • edpeloquin
    • Joined on 01-22-2007, 8:39 PM
    • Posts 4
    Thank you Jessica for the post, Does the showModalDialog pop up a window with a seperate web page in it?  If so how do I then pass the string value for whatever reason they enter back to the delete function?  I had originally tried using button.attributes.add(.....onclientclick return inputDialog etc.) this showed up but it still did postback even when I clicked on the cancel button.  All I'm trying to do is prompt the user for a string value when they click the delete button and then when ok is clicked it continues the event.
  • Re: Getting user input with pop up's

    01-24-2007, 1:22 AM

    hi,

    u can use a confirm dialog to make sure that whether the user want to delete the row

    and in the GridView

    try this

     <asp:GridView ID="GridView1" runat="server" OnRowDeleting="GridView1_RowDeleting">
            <Columns>
            <asp:TemplateField><ItemTemplate>
            <asp:LinkButton ID="delete" runat="server" Text="delete" CommandName="Delete" OnClientClick="javascript:return confirm('Are you sure you want to delete ?');">></asp:LinkButton>
            </ItemTemplate></asp:TemplateField>
            </Columns>
            </asp:GridView>

    read about the following article, hope you can get more information

    Introduction

    There is a lot of good code tutorials out there that teach you how to enable javascript confirmation dialog box in asp.net 1.1 ( easily done in asp.net 2.0 ). However there is none that show you how to do it if your button/link is in a datagrid. This article addresses this gap. Let m_dg1 be the datagrid that will contain a list of linkbutton (lkDelete2) in our case used to delete a specific row of data in your table. Add the following column in your Datagrid.

    <asp:datagrid id="m_dg1" style="Z-INDEX: 111; LEFT: 208px; POSITION: absolute; TOP: 224px"
                    runat="server" >
                    <Columns>
    
                        <asp:TemplateColumn HeaderText="Delete Referral 1">
                            
                                <asp:LinkButton ID="lkDelete2" Runat="server" CommandName="Delete2" OnClient="return confirm('Are you sure you want to delete ?');">
                            Delete
                        </asp:LinkButton>
                            
                        </asp:TemplateColumn>
                    </Columns>
                </asp:datagrid>
    

    You can then go on to add an ItemCreated Event handler for that datagrid. For the sake of our exercise we will call this hander OnItemCreate If you don't know how to add an event handler for your datagrid Do the following: - Select your DataGrid in Design mode ( Not HTML) - In the Property window click on the event Button ( the Lightening buttonn Yellow on top ). - Type the name of the function that you want to handle any specific event ( in our case the event is ItemCreated and the function name is OnItemCreate. - Hit Enter. We are almost done. Now in the code behind fill in the OnItemCreate function with the following code

            private void OnItemCreate(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                Control clb = (Control)e.Item.FindControl("lkDelete2");
                if(clb!=null && clb.GetType() != typeof(LinkButton))
                    return;
                LinkButton lb = (LinkButton)clb;
                if(lb != null)
                {
                    lb.Attributes.Add("onClick", "return confirm('Are you sure you want to delete ?');");
                }
            }
    

    Done. Explanations ? Well when the Control is rendered during the Databind an ItemCreated event is fired for each row. When ever that happens I fetch for my control name when I find it , I add the appropriate javascript to it. Not that magic actually. What is annoying is Y wont VS let me directly add it in the ASP code. But then again who am I to discuss Microsoft ways. This issue if fixed in asp.net 2.0.

    Jessica Cao
    Sincerely,
    Microsoft Online Community Support


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: Getting user input with pop up's

    01-24-2007, 8:54 AM
    • Loading...
    • edpeloquin
    • Joined on 01-22-2007, 8:39 PM
    • Posts 4

    Thanks again jessica for the information.  I've successfully implemented the confirm dialog box and that is what I'm currently using but I need the user to enter a reason as well.  That is why I needed to use something like an input dialog.  My current code for the gridview is:

    <asp:GridView ID="grdMyReservations" SkinID="gridviewSkin" runat="server" AutoGenerateColumns="False" DataKeyNames="ReservationId">
        <Columns>
            <asp:TemplateField HeaderText="Options" ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Select" Text="Edit" OnClick="lnkEdit_Click"></asp:LinkButton><br />
                    <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Select" 
                        Text="Cancel" OnClick="lnkCancel_Click" OnClientClick="return confirm('Cancel this reseravtion and notify any passengers of the cancellation?');"> </asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:ImageField HeaderText="Vehicle" DataImageUrlFormatString="../Upload_Images/{0}.jpeg" DataImageUrlField="PictureName" NullImageUrl="~/Upload_Images/noImage.jpeg">   
            </asp:ImageField>
            <asp:BoundField DataField="VehicleId" HeaderText="ID" Visible="False" SortExpression="VehicleId" />
            <asp:BoundField DataField="Description" HeaderText="Name" SortExpression="Description" />
            <asp:BoundField DataField="ActStartDate" HeaderText="Start Date" SortExpression="ActStartDate" > 
                <ItemStyle Width="100px" />
                <HeaderStyle Width="100px" />
            </asp:BoundField>
            <asp:BoundField DataField="ActEndDate" HeaderText="End Date" SortExpression="ActEndDate" >
                <ItemStyle Width="100px" />
                <HeaderStyle Width="100px" />
            </asp:BoundField>
            <asp:BoundField DataField="StartLocation" HeaderText="Leaving" SortExpression="StartLocation" />
            <asp:BoundField DataField="EndLocation" HeaderText="Destination" SortExpression="EndLocation" />
        </Columns>
    </asp:GridView>

     How can I replace the confirm with an input dialog and retrieve the entered value.  It will eventually be sent to all passengers to let them know the reason for the reservation cancellation.

  • Re: Getting user input with pop up's

    01-25-2007, 8:36 PM
    Answer

    hi edpeloquin,

    I have found an article for you, hope it can help u

    This article shows a modal popup dialog window which passes and returns multiple parameters. This sample creates parent and child webforms. The child webform is called modally by the parent passing multiple values to the child form. The child form displays the passed values allowing them to be edited and then returns the altered values back to the parent when finished. The child form is modal to only the parent form. To make the child modal to the entire desktop, see the below final note.

    http://www.codeproject.com/aspnet/Modal_Dialog.asp

    Jessica

    Jessica Cao
    Sincerely,
    Microsoft Online Community Support


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter