Click here to Skip to main content
15,846,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Problem that I am facing is that when a page is called for the first time javascript isn't executed but if I just refresh the page the script works fine.
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<svotrucking.models.driverdtl>" %>

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">


      <script src="../../scripts/jquery-1.8.0.min.js"></script>
    <script src="../../scripts/"></script>
    <link rel="stylesheet" href="../../Content/css/" />

	<link href="../../Content/css/mobiscroll-2.0.3.custom.min.css" rel="stylesheet" type="text/css" />
	<script src="../../scripts/mobiscroll-2.0.3.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {
            $("#LoadTime").scroller({ preset: 'datetime', dateFormat: "yy-mm-dd" });

Updated 3-Oct-12 2:34am
huotari 3-Oct-12 8:06am    
Have you checked that during the first load the scripts are actually loaded
Qadeer Ahmed Khan 3-Oct-12 8:13am    
Can you tell me to how to check that? but if it doesn't load at first then how does just refreshing the page makes it load the script?
huotari 3-Oct-12 8:23am    
Well you can check it by looking at the page source and clicking on the script url. If you get a 404 content not found then it is not loaded.
Qadeer Ahmed Khan 3-Oct-12 8:29am    
Yes I think problem is with the script loading because when I get to this page I can see the script for the previous page but clicking the refresh button shows the current page script. Do you have any idea how to fix it I am using MVC 2 and that's how I am calling the page.

return View("DriverDtlAdd",obj);
huotari 3-Oct-12 8:44am    
So during the first load you cant see this pages scripts at all?

1 solution

$("#LoadTime").scroller({ preset: 'datetime', dateFormat: "yy-mm-dd" });

LoadTime is not defined on the same page. If the objects are not loaded any modification through script will not work. Define the LoadTime element on the same page and check.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900