I am writing a javascript
function ValueChanges()
{
Parent = document.getElementById('<%= grvMultiChoiceAnswerList.ClientID %>');
var items = Parent.getElementsByTagName('textarea');
var chkboxControl = Parent.getElementsByTagName('checkbox');
for (i = 0; i < items.length; i++) {
var h开发者_Python百科dnTextControl, hdnExplanation;
hdnTextControl = (items[i].id).replace("txtText", "hdnText");
hdnExplanation = (items[i].id).replace("txtExplanation", "hdnExplanation");
if (items[i].id.split("_")[5] == "txtText") {
if (items[i].value != document.getElementById(hdnTextControl).value) {
var ssave = window.confirm('Your changes are not saved. Do you want to save your changes before you exit.')
if (ssave == true) {
document.getElementById('<%=btnUpdate.ClientID%>').click(); // I WANT TO REPLACE THIS LIKE SO MY DELEGATE GETS FIRE
return false;
}
else
return true;
}
}
}
I have a delegate
grvMultiChoiceAnswerList.RowUpdating += delegate(object obj, GridViewUpdateEventArgs args)
{
SaveFields();
if (ReloadContent != null)
ReloadContent(null, EventArgs.Empty);
};
Now i want to call this delegate in my java script and want to replace document.getElementById('<%=btnUpdate.ClientID%>').click(); line so my delegate get fire when if(ssave==ture) condition is true
In order to access to "methods" on the server from the javascript you need to make a postback with your javascript like :
__doPostBack('MyBtn','');
As far as the server goes , this will act the same as
document.getElementById('<%=btnUpdate.ClientID%>').click();
, but as for the client, it will skip any javascript linked with the click on the button.
To access server side, you need to simulate the firing of an event from your javascript so that the asp.net page can recognise it and cling to it. Add the update column of the grid view and look at the javascript generated, it will give you the clue to know what to trigger within the dopostback. After you might need to keep the column but be able to hide it using css.
精彩评论