Why would there be a need to call a JavaScript function from code behind? -
i been looking around online calling javascript function code behind, examples have seen registerstartupscript method on click event. why want or need instead of wiring onclientclick event? there ever need call javascript function code behind?
registerstartupscript 1 of many options infinite number of scenarios. in end, can registerstartupscript can done way. used consider convenience, avoid it, separation of concerns , such higher stages of "enlightenment".
mainly see registerstartupscript still in use custom controls expected wire without end-user knowing them. see ajaxcontroltoolkit, updatepanel, scriptmanager, etc. require javascript obvious reasons not expect include client-side scripts or register them.
random scenario:
if (user.identity.name == "frank") registerstartupscript(this, gettype(), "frank", "alert("hey frank, owe me money!");
alternative scenario, have server-side set hidden field.
<input type="hidden" id="name" value="<%= user.identity.name %>" /> <script type="text/javascript"> $(document).ready(function() { if ($("#name").val() == "frank") alert("hey frank, owe me money!"); }); </script>
Comments
Post a Comment