Monday, February 14, 2011

By-rohitsuri84@gmail.com


Add a javascript method in aspx page--
<script type='text/javascript'>

function GetMessage(datakey, index) {
PageMethods.serversidewebmethod(datakey, index, OnGetMessageSuccess, OnGetMessageFailure);
document.getElementById('button' + index).style.display = 'none';
document.getElementById('done' + index).style.display = 'block';
document.getElementById('done' + index).style.backgroundColor = '#FFFF99';
}
function OnGetMessageSuccess(result, userContext, Getmessage) {


}
function OnGetMessageFailure(error, userContext, Getmessage) {
alert(error.get_message());
}


</script>

// In code behind file
 Add a web method that you want to call from javascript--

[System.Web.Services.WebMethod]
public static string serversidewebmethod(string datakey, int index)
{
string _connStr = GetConnectionString();
dbclass db;
db = new dbclass(_connStr, "sp");
db.AddInParameter("@var1", datakey);
db.AddInParameter("@var2", PType);
db.AddInParameter("@var3", UserID);
db.ExecuteNonQuery();
db.Dispose();
return "Successful";
}
//Return successful if no execption
}

Say You Add a html control on runtime
sb.Append("<img src=\"../" + this.imgURL + "\" Style=\"Height:60px; Width:120px;\" title=\"" + this.dddTxt + "\"/><br><div id ='button" + id + "' align='center'> <input type='button' id = " + id + " value='Add it now' onclick=\"GetMessage('" + gv.DataKeys[id].Value + "'," + id + ");return false;\" /></div><div id = 'done" + id + "' style='display:none;font-weight:bold;' align='center' >Added</div></td>");

1 comment:

Powered by Blogger.

Followers

Best Price Amazon Portal

Amazon Best Offers