Aggiungo JQuery alla mia pagina Web asp.net. Non riesco a capire l'ordine di esecuzione in modo complettamente. scrivo il codice foolowing per testarlo. In ogni caso, Page Load verrà eseguito prima di $ (document) .ready(), è giusto?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('Hell');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = "World";
}
}
}
Il codice lato server deve finire in esecuzione affinché la pagina venga trasmessa al client (browser). A questo punto, è possibile eseguire il codice client (Javascript). – Oded