开发者

Call JQuery Success Div if Record Save/ Update successfully from GridView Template

I have one GridView Control of Asp.net and In Template column of that i have Insert & Update Link Button along with Cancel and Edit.

Now, I want to fire the Query which shows the message "Records Inserted/ Updated Successfully" if Insert or Update button fired and Record saved in database successfully. else message should be like Exception or "record not saved please try again"

Can anyone tell me where and how should i write code and script register? to achieve the same?

my Code sample is somewhat like

protected void grvCategory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Insert")
            {
                string footerCategoryName = ((TextBox)grvCategory.FooterRow.FindControl("txtFTCategoryName")).Text;
                string txtTransactionTypeId = ((DropDownList)grvCategory.FooterRow.FindControl("ddlFTTransactionTypeName")).SelectedItem.Value;
                string footerBasePrice = ((TextBox)grvCategory.FooterRow.FindControl("txtFTPrice")).Text;
                try
                {
                    string insertCategory = string.Format(SQLQuery.InsertCategory, footerCategoryName, txtTransactionTypeId, footerBasePrice, HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name);
                    int returnV开发者_开发问答alue = SqlHelper.ExecuteNonQuery(ProjectConfig.ConnectionString, CommandType.Text, insertCategory);
                    if (returnValue > 0)
                    {
                        lblMessage.Text = "Record Inserted Successfully";
                        grvCategory.FooterRow.Attributes.Add("onclick", "javascript:callme();");

                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

protected void grvCategory_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblITTransactionTypeId = (Label)e.Row.Cells[2].FindControl("lblITTransactionTypeId");

                Label lblITTransactionTypeName = (Label)e.Row.Cells[2].FindControl("lblITTransactionTypeName");
                if (lblITTransactionTypeName != null)
                    lblITTransactionTypeName.Text = StringEnum.GetStringValue((ProjectEnum.TransactionType)(Enum.Parse(typeof(ProjectEnum.TransactionType), lblITTransactionTypeId.Text.ToString())));

                DropDownList ddlETTransactionTypeName = (DropDownList)e.Row.Cells[3].FindControl("ddlETTransactionTypeName");
                if (ddlETTransactionTypeName != null)
                    FillTransactionTypeDropDown(ddlETTransactionTypeName, lblITTransactionTypeId.Text);

                DropDownList ddlFTTransactionTypeName = (DropDownList)e.Row.Cells[3].FindControl("ddlFTTransactionTypeName");
                if (ddlFTTransactionTypeName != null)
                    FillTransactionTypeDropDown(ddlFTTransactionTypeName, string.Empty);
            }
        }


Why don't you just bung a literal in your success div and output some text to it on the server side when you know if the records been successful. Then if that div has content let jquery handle any nice effects/animations/styles you mite want to apply to that div when the page renders.


There are a lot of jQuery plugins for displaying a notification: NOTIFICATION

You may use any of them. For instance, fir notice plugin (JQUERY NOTICE) you can apply following code to display message from server: ClientScript.RegisterStartupScript(typeof(Page), "Notice", "jQuery.noticeAdd({text: 'Hello ,World!'});", true);

Or if your controls placed in UpdatePanel: ScriptManager.RegisterStartupScript(this, typeof(Page), "Notice", "jQuery.noticeAdd({text: 'Hello ,World!'});", true);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜