In my implementation using Master and Content page, I have a client side function:
<script type="text/javascript">
function StateChange(txtState) {
var state = document.getElementById(txtState);
PageMethods.StateSelectionChange(state.value, OnSuccess, onFailed);
}
function OnSuccess(state, userContext, methodName) {
alert(state);
}
function onFailed(state, userContext, methodName) {
alert(state);
}
</script>
accompanied by server side code:
public static string StateSelectionChange(string state)
{
//txtCity.Text = "";
//if (txtState.Text != "")
//{
// SqlDataReader dr = cm.Allstate(txtState.Text);
// if (dr.Read())
// {
// con.Close();
// AutoCompleteExtender2.ContextKey = txtState.Text;
// txtCity.Enabled = true;
// txtCity.Focus();
// }
// else
// {
// con.Close();
// ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('State is not exist');", true);
// txtState.Text = "";
// txtState.Focus();
// }
//}
return (state);
}
I am facing an issue where I cannot access the commented part of the code (textbox and class main function) due to declaring the function as static. Removing the static word from the function would prevent it from being called from the client side.
My ultimate goal is to be able to call a non-static function from the client side through JavaScript/ajax request.