views:

211

answers:

1

I have started using jquery in one of my new asp.net webform application... I want to display a success message after an insert on a button click event... Here is my link button..

 <asp:LinkButton ID="LbOk" runat="server" CssClass="regular" 
 onclick="LbOk_Click" OnClientClick="return validateEmployee();" >
</asp:LinkButton>

And my OnClick Event:

protected void LbOk_Click(object sender, EventArgs e)
{
 if (inserttoDB())
        {
           // display successfully inserted using jquery
        }
        else
        {
          //  display Insert Failed using jquery
        }
}
+2  A: 

The code you've posted makes no sense, since the LbOk_Click requires a post-back. In that case the whole page is rendered again. So you can/should use server side code to display the message.

The correct way to do it will be to use an Ajax call. Upon completion of the Ajax call, the message will be displayed. Something like this:

 <asp:LinkButton ID="LbOk" runat="server" CssClass="regular" 
  OnClientClick="updateEmployee();" >
</asp:LinkButton>

and the client code:

function updateEmployee() {
  if (validateEmployee() {
    $.ajax({
       type: 'POST',
       url: url,
       data: data,
       success: function() {
          // display message here
       }});
  }
}

The Ajax server side could be implemented with an Ajax enabled WCF service.

kgiannakakis
@kgiannakakis ya u was right it didnt work....
Pandiya Chendur
@kgiannakakis http://stackoverflow.com/questions/2228474/what-are-the-pros-and-cons-when-choosing-ajax-enabled-wcf-service-in-an-asp-net-wand please suggest me a solution..
Pandiya Chendur