Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call my cmdSave_Click button to run from my javascript in aspx

Status
Not open for further replies.

Gzk2010

Programmer
Aug 17, 2010
48
US
how to call my cmdSave_Click button to run from my javascript in aspx.

Ok so now it is working and now when the javascript actually function checkSave() runs and the window.confirm pops up, I want it to really save. Before I was being sure I got that far.

my Jscript runtime error Microsoft JScript runtime error: "window.document.frmTest' is null or not an object"

it errors on this line that is in the script below: window.document.frmTest.cmdSave();

I am NOT suprised, it is from cmdSave_Click() in my c# code behind page. How do I call that C# code behind event handler from Jscript?

Here is my javascript in my aspx page:

<script language="javascript" type="text/javascript">
var isDirty;
isDirty = 0;
function setDirty() {
isDirty = 1;
}
function checkSave() {
var sSave;
if (isDirty == 1) {
sSave = window.confirm("You have some changes that have not been saved. Click OK to save now or CANCEL to continue without saving.");
window.document.frmTest.cmdSave();
}
else
{
return true;
}
}
}
</script>







Thanks in advance!
Adam
 
you don't. javascript run's on the client's browser. the click event handler runs on the server. the 2 never directly communicate with each other.

what you can do is have javascript call a web service or page web method. this is usually in conjunction with ajax requests.

javascript send a request to the servre (the url).
the server translates the request and determines what resource/component should handle it.
the request is processed by the server and the server returns a response.
the client receives the response and processes the results.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
You can have an ajax call to a generic handler. the jQuery framework makes this very simple.
 
very true, it doesn't matter what the server resource is. javascript just needs to make a request to that url.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top