If you use jquery you could do like below
$.ajax({
type: "POST",
url: "index.aspx/lvimgclick",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ value: "test" }),
dataType: "json",
success:function(result){
if(result.cssclass)
{
$('#<%= lvlink1.ClientID %>').addClass(result.cssclass);
}
}
});
In WebMethod
public class CustomResult
{
public string output{ get; set; }
public string cssclass{ get; set; }
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static CustomResult lvimgclick()
{
var result=new CustomResult{output="hi", cssclass="lv-under1"}
return result;
}
Note:
Sometimes you may need to access the data with d
, which was added by framework. like result.d.cssclass
EDIT:
In case if you want to update multiple link buttons, have a common css class defined for it in aspx.
<asp:LinkButton ID="lnk1" runat="server" CssClass="menu" Text="Home" />
<asp:LinkButton ID="lnk2" runat="server" CssClass="menu" Text="AboutUs" />
Then in your ajax call's success callback use class selector and update.
success:function(result){
if(result.cssclass)
{
$('a.menu').addClass(result.cssclass);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…