views:

39

answers:

2

Hi, I have a LinkButton click event in asp.net 3.5 that I must assess whether a value exists and return a alert. I have no idea how you can do. I think we need to Ajax Can someone help me

Thanks

A: 

Just implement the OnClientClick handler for the LinkButton assuming that the value you want to check is available client side:

OnClientClick="if $('#yourID').val() == 'something')
    return confirm('Are you sure you want to override this lock?');
    else return true;"

If it is not available client side then you would need to do an ajax call to check the value and replace the if check in the example above with it or have your server side code add an inline javascript alert.

Kelsey
+2  A: 

Here is a pretty simple solution without getting too involved with a lot of AJAX.

If you have your link button in your page:

<asp:LinkButton id="myButton" Text="Click me" OnClick="myButton_Click" runat="server" />

Add an event handler in your page's code behind:

protected void myButton_Click(object sender, EventArgs e)
{
    // Check some stuff on the server...

    ClientScript.RegisterStartupScript(this.GetType(), "alert", "myJsMethod()", true);
}

This example will call a JavaScript function called myJsMethod on your page which you can then call any JS you like including your alert().

Wallace Breza