My goal is to initiate a postback using JavaScript and also pass event arguments. While I have managed to trigger the postback successfully, I am facing issues with passing event args.
The function below is not functioning as expected. It seems to be encountering an issue with the args
parameter in
ClientScript.GetPostBackEventReference
.
<script type="text/javascript">
function TriggerServerSideClick(args) {
//btnDummy is an ASP.NET server-side button control
<%=ClientScript.GetPostBackEventReference(btnDummy, args , true)%>
//I also tried this -> <%= 'ClientScript.GetPostBackEventReference
// (btnDummy,' + args + ', true)' %> ,
// but it does not seem to work.
}
</script>
What am I overlooking in this scenario?
I understand that the following approach works:
__doPostBack('btnDummy', args);
However, I prefer to avoid using __doPostBack
since it may change in the future, and I want to explore utilizing
ClientScript.GetPostBackEventReference
instead.
Thank you for your assistance.
@Brian: I appreciate your suggestion on the placeholder method, but unfortunately, I encountered a JavaScript error (Message: Expected ';').
Here is a snippet from the viewsource:
var postbackUrl = '__doPostBack('ctl00$MainContent$btnDummy','{0}')';
function TriggerServerSideClick(args) {
var url = String.format(postbackUrl, args);
eval(url);
}