Possible Duplicate:
Javascript that executes after page load
i have application in asp.net 4.0
i have javascript to display client zone offset into text box:- `
<script type="text/javascript">
function GetTimeZoneOffset() {
var d = new Date()
var gmtOffSet = -d.getTimezoneOffset();
var gmtHours = Math.floor(gmtOffSet / 60);
var GMTMin = Math.abs(gmtOffSet % 60);
var dot = ".";
var retVal = "" + gmtHours + dot + GMTMin;
document.getElementById('<%= offSet.ClientID%>').value = retVal;
}
</script>
`
Html MarkUp
<asp:HiddenField ID="clientDateTime" runat="server" />
<asp:HiddenField ID="offSet" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></body>
How can I call this function on page load so that I can display offset into textbox?
To include a JavaScript function, it is as simple as include a <script> tag and define the function inside the script block. Now, to call the function, add an onclick event on the employee name hyperlink and call the function.
Hi, You can use ASP.Net Ajax ScriptManager to register startup script. In this startup script you can call a web service or page method that will fetch some data from server and then change your html controls on client side with the data from server.
Page_Load runs on the server, and jquery runs on the client. as suggested, you render javascript code included in the html page you are sending to the browser. once the browser loads the page, it will make the ajax call. this will all occur be after the server is done with the page (after Page_Unload).
Calling JavaScript function on code behind i.e.
On Page_Load
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);
If you have UpdatePanel
there then try like this
ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With