Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am wroking to add a gridview to my website with using the javascript, I have used
- commandField and added the Delete, and Edit Buttons, with alert message of javascript to show the messagebox.
- also used the navigation for each 5 pages.

All that is used inside UpdatePanel of Ajax, but whenever I click Edit or Delete buttons the alert message does not appear, and if I removed the UpdatePanel it works but the navigation load the page!

Note:
I have tried to use the triggers inside the update panel;

XML
<asp:PostBackTrigger ControlID="GridView1" />

that makes the buttons work, but stops the un-moving or un-loading of the page.

also used
XML
<asp:AsyncPostBackTrigger ControlID="GridView1" />

the buttons stop working, but the the navigation works.

Although, I cannot use both triggers.

Please Help!
Posted
Comments
Sandeep Mewara 31-May-12 15:08pm    
How have you implemented "the alert message does not appear"?
Nuha IT 1-Jun-12 11:49am    
Yes, it does not appear when UpdatePanel is used.
Sunasara Imdadhusen 1-Jun-12 6:05am    
Please provide snippet of code so we can try to what exact problem you have.

1 solution

Sunasara this is the code:

XML
<script type="text/javascript">
        function ToggleRowColor(element) {
            if (element.style.backgroundColor == 'cyan') {
                element.style.backgroundColor = '#5691da';
                element.style.cursor = 'hand';
                element.style.textDecoration = 'none';
            }
            else {
                element.style.backgroundColor = 'cyan';
                element.style.cursor = 'hand';
                element.style.textDecoration = 'underline';
            }
        }
    </script>

<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
    </asp:scriptmanager>
    <asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
        <contenttemplate>
            <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" datakeynames="Subj_id">
                CssClass="cntrdatag" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True"
                RowStyle-BackColor="#5691da" OnRowDataBound="GridView1_RowDataBound" OnRowUpdated="GridView1_RowUpdated"
                OnRowUpdating="GridView1_RowUpdating" OnRowDeleted="GridView1_RowDeleted" Font-Size="Large"
                Width="626px">
                <columns>
                    <asp:commandfield showeditbutton="True" showdeletebutton="True" headerstyle-width="180">
                        ButtonType="Button" ShowCancelButton="true"></asp:commandfield>
                    <asp:boundfield datafield="subj_id" headerstyle-backcolor="#08346b" headertext="Subject-ID">
                        SortExpression="subj_id" HeaderStyle-Width="100" ReadOnly="true">
                        <HeaderStyle BackColor="#08346b" Width="100px" ForeColor="White" BorderColor="Black">
                        </HeaderStyle>
                    </asp:boundfield>
                    <asp:boundfield datafield="subj_name" headerstyle-backcolor="#08346b" headertext="Subject-Name">
                        SortExpression="subj_name" HeaderStyle-Width="200">
                        <HeaderStyle BackColor="#08346b" Width="200px" ForeColor="White" BorderColor="Black">
                        </HeaderStyle>
                    </asp:boundfield>
                </columns>
                <pagertemplate>
                Current Page: <%=GridView1.PageIndex+1%>
                    Number of Pages:
                    <%=GridView1.PageCount %>
                    <br />
                    <asp:button id="btnFirst" runat="server" commandname="Page" cssclass="btn" commandargument="First">
                        Text="<<" />
                    <asp:button id="btnPrev" runat="server" commandname="Page" cssclass="btn" commandargument="Prev">
                        Text="<" />
                    <asp:button id="btnNext" runat="server" commandname="Page" cssclass="btn" commandargument="Next">
                        Text=">" />
                    <asp:button id="btnLast" runat="server" commandname="Page" cssclass="btn" commandargument="Last">
                        Text=">>" />
                </asp:button></asp:button></asp:button></asp:button></pagertemplate>
                <rowstyle backcolor="#5691da"></rowstyle>
            </asp:gridview>
        </contenttemplate>
    </asp:updatepanel>

</script>



-----------------------------

C#
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        if (e.Exception != null)
        {
            string x = e.Exception.Message; ;
            Response.Write(@"<script language='javascript'>alert('" + x + "');</script>");
        }
        else
        {
            Response.Write(@"<script language='javascript'>alert('Updated Successfully');</script>");
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900