Sunday, August 2, 2009

How to call a ASP program form within javascript?

Have a button, and on onClick event, call a javascript function, inside javascript function, what to call a ASP program. Does anyone know how to do it? what is syntax?





Thanks

How to call a ASP program form within javascript?
ASP is server-side scripting while JavaScript is client-side, so there really isn't a way exactly to call ASP on with an onclick trigger because the page has already been drawn and is static.





however, a work-around could be to have a form who's action is set to an ASP page and then using the following line from javascript you could submit the form that calls the ASP.





even if you did a post back to yourself you at least give the server-side scripting a chance to execute as it re-drew the page.





EXAMPLE:





%26lt;%


if request.servervariables( "request_method" ) = "POST" then


'the request_method is a great way to detect if you're


'being posted to or drawing the page for the first time


end if


%%26gt;


%26lt;html%26gt;


%26lt;head%26gt;


%26lt;script language=javascript%26gt;


function callASP()


{


document.myform.submit();


}


%26lt;/script%26gt;


%26lt;/head%26gt;


%26lt;body%26gt;


%26lt;form name=myform action=mypage.asp method=post%26gt;


%26lt;input type=text name=yourMiscTextFields%26gt;


%26lt;input type=button onclick=javascript:callASP();%26gt;


%26lt;/form%26gt;


%26lt;/body%26gt;


%26lt;/html%26gt;





hope this helps! good luck!








***JUST SAW YOUR UPDATE***


you could program your third button as follows:


%26lt;input type=button value=Click-Me onclick= javascript:window.navigate( 'pagename.asp' );%26gt;
Reply:i assume you want to call an ASP page... i'd probably do something like openWindows("/mypage.asp"); as your on click event code.. you may want to check the exact synatx of that but it should work.
Reply:Not able to get u completely !! Let me try ...





On Button Click u r calling some JavaScript function ..in the fuction...u can call the asp page ..by setting the action to ur asp page !!





Add some more details to ur question ..??
Reply:This doesn't make any sense. You can have javascript on an asp page, but you can't call an asp program from javascript. You can redirect to an asp page. ASP - Active Server Pages - not programs! Come on now
Reply:using Addattribute.


No comments:

Post a Comment