Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i want to call a c# function from html buton's value without adding any javascript
C#
<input type="button"  runat="server" id="test" name="test" value='<%=Resource.Language("_Description") %>' />

But its not calling my Language function which is on root folder on one of my Resource Class but if i am using the same text in asp label like this
C#
<asp:Label ID="test" runat="server><%=Resource.Language("_Description") %>

this is calling my function and returns string, but the same thing is not being on button.

Waiting for your kind reply.
thanks
Posted
Updated 13-Sep-13 0:40am
v2

1 solution

for calling server side function from html button you need to call like this.

you need to make that function static and mark that with webmethod attribute.

then write javascript function on your design side that will fire a ajax request to call that function from your code behind as you call any webservice function from your side using jquery/javascript ajax request.

Your javascript function look like this.

<script type="text/javascript">
function DeleteData() {
$.ajax({
type: "POST",
url: "Default.aspx/DeleteData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert("Your function called sucessfully");
//if your Codebehind method return something then that data or result will be accessed using .d attribute of msg
//like this...

//alert("Your method return data is ..." + msg.d);
},
error: function (msg) {
alert("There's some error in calling your function.");
}
});
return false;
}
</script>


and your code behind function like this...



[WebMethod]
public static void DeleteData()
{
//your code
}
 
Share this answer
 
Comments
vishvadeepak 13-Sep-13 6:58am    
i directly want to call the c# function from Value of html button so that i can get the text which is returned from the method of c#

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