所以我最近开始使用 asp.net 和 c#,我正在尝试做一个日程安排程序,当我在一个简单的页面上创建调度程序时,没有使用母版页,它工作正常,现在我正在尝试创建同一页面,但使用母版页。
我一直在寻找问题,我认为问题与母版页 ID 有关是与内容中的 ID 相关联。这是我的代码。我拥有的是一个母版页,在内容上我有一个名为 webdatagrid 的基础设施控件,在网格中我有一个列 ID,以及一个内部包含组件的列......该组件的代码如下:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Segmentos.ascx.cs" Inherits="IdOntime.Segmentos" %>
<style type="text/css">
.divttt
{
background-color:#fff;
width:30px;height:32px;
float:left;
border-bottom:solid 1px #000;
border-top:solid 1px #000;
border-left:solid 1px #000
}
</style>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt">
</div>
<div class="divttt" style=" border-right:solid 1px #000">
</div>
基本上是 24divs 在一行中......当我点击一个颜色时,颜色会变成黑色或白色,具体取决于当前颜色。
Webform5.aspx 的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="IdOntime.WebForm5" %>
<%@ Register src="~/Segmentos.ascx" tagname="Segmento" tagprefix="uc1" %>
<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<!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">
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"> </script>
<link rel="stylesheet" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" />
<script type="text/javascript">
$(function() {
var hi;
var qt;
var rows;
var horas = [];
var qthoras = [];
var qt = 0;
var todo = 0;
var show = 0;
var columns, alldivs;
var iduser, row, divshorario, teste, grid, rows;
$("#Button1").click(function(evt) {
evt.preventDefault();
grid = $find('<%= this.WebDataGrid1.ClientID %>');
rows = grid.get_rows();
//alert("rows lenght:" + rows.get_length());
for (i = 0; i < rows.get_length(); i++) {
//alert(i);
row = rows.get_row(i)
iduser = row.get_cell(0).get_text();
divshorario = row.get_cell(1).get_text();
teste = row.get_cell(1).get_text();
//alert(teste);
alldivs = $(divshorario).filter('.divttt');
var elementsLength = alldivs.length;
$.each(alldivs, function(j, l) {
//alert(j);
var x = $(l).css('backgroundColor');
if (x == 'black') {
if (todo == 0) {
alert("k:" + j);
hi = j;
todo = 1;
show = 0;
}
qt++;
}
else {
if (show == 0 && todo == 1) {
alert("valor da hora inicial:" + (hi) + " e a hora final:" + (j));
$.ajax({
type: "POST",
url: "WebForm5.aspx/DeleteUploadedFile",
data: "{ID: '" + iduser+ "', horai:'"+hi+"' , horaf:'"+j+"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
},
error: function(response) {
}
});
show = 1;
}
todo = 0;
qt = 0;
}
});
show = 0;
}
});
});
</script>
<script type="text/javascript">
var myArray = [];
$(window).load(function() {
var mousedown = false;
var bid, bid2;
var trid, trid2;
var color;
var row;
trid = $(this).closest('tr').attr('id');
row = $('#' + trid);
$(document).mousedown(function() { mousedown = true; });
$(document).mouseup(function() { mousedown = false; });
$('div.divttt').mousedown(function() {
//bid = this.id; // button ID
//trid = $(this).closest('tr').attr('id'); // table row ID
trid = $(this).closest('tr').attr('id');
//alert(trid);
myArray.push(trid);
var b = $(this).css("background-color");
// alert(b);
if (b == 'rgb(255, 255, 255)') {
$(this).css('backgroundColor', 'black');
color = 'black';
// alert("branco");
}
else if (b == 'rgb(222, 222, 222)') {
//alert('cinza');
$(this).css('backgroundColor', '#DEDEDE');
///alert("teste");
}
else {
$(this).css('backgroundColor', 'white');
color = 'white';
}
});
$('div.divttt').mouseover(function() {
if (mousedown) {
// var b = $(this).css("background-color");
// alert(b);
// bid2 = this.id; // button ID
trid2 = $(this).closest('tr').attr('id'); // table row ID
//alert(trid2+"||"+trid);
if (trid2 == trid) {
$(this).css('backgroundColor', color);
}
}
});
});
</script>
<title></title>
<style type="text/css">
#WebDataGrid1
{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
<div>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px"
AutoGenerateColumns="False">
<Columns>
<ig:BoundDataField DataFieldName="ID" Key="ID" Width="50px">
<Header Text="ID" />
</ig:BoundDataField>
<ig:TemplateDataField Key="Segmentos" Width="745px">
<Header Text="Segmentos" />
<ItemTemplate>
<uc1:Segmento ID="Segmento1" runat="server"></uc1:Segmento>
</ItemTemplate>
</ig:TemplateDataField>
</Columns>
</ig:WebDataGrid>
<asp:Button ID="Button1" runat="server" ClientIDMode="Static" Text="Button" />
</div>
</form>
</body>
</html>
在母版页 master1.page 中,我在头部声明了这一点:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" />
<script type="text/javascript">
function() {
var mousedown = false;
var bid, bid2;
var trid, trid2;
var color;
var row;
$(document).mousedown(function() { mousedown = true; });
$(document).mouseup(function() { mousedown = false; });
$('div.divttt').mousedown(function() {
//bid = this.id; // button ID
//trid = $(this).closest('tr').attr('id'); // table row ID
trid = $(this).closest('tr').attr('id');
alert(trid);
});
};
</script>
...
<asp:ContentPlaceHolder ID="cphMain" runat="server">
</asp:ContentPlaceHolder>
...
在页面 asHorariosEscalas.aspx 我有这个:
<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="AsHorariosEscalas.aspx.cs" Inherits="IdOntime.asHorariosEscalas" %>
<%@ MasterType VirtualPath="Site1.master" %>
<%@ Register src="~/Segmentos.ascx" tagname="Segmento" tagprefix="uc1" %>
<%@ Register Src="SelPessoas.ascx" TagName="SelPessoas" TagPrefix="uc1" %>
<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.ListControls" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics2.WebUI.WebDataInput.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.WebDataInput" TagPrefix="igtxt" %>
<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.NavigationControls" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.EditorControls" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics2.WebUI.WebDataInput.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.WebDataInput" TagPrefix="igtxt" %>
<%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>
<%@ Register Assembly="Infragistics2.WebUI.UltraWebNavigator.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.UltraWebNavigator" TagPrefix="ignav" %>
<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.LayoutControls" TagPrefix="ig" %>
<asp:Content ID="Content2" runat="server" contentplaceholderid="cphMain" >
<div runat="server" style="
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;">
<ig:WebDataGrid ID="WebDataGridPlaneamentoHorarios" runat="server" Height="400px"
AutoGenerateColumns="False" Width="1000px" >
<Columns>
<ig:BoundDataField DataFieldName="ID" Key="ID" Width="50px" >
<Header Text="ID" />
</ig:BoundDataField>
<ig:TemplateDataField Key="Segmentos" Width="745px">
<ItemTemplate>
<uc1:Segmento ID="Segmento1" runat="server" />
</ItemTemplate>
<Header Text="Segmentos" />
</ig:TemplateDataField>
</Columns>
</ig:WebDataGrid>
<asp:Button id="Button1" runat="server" Text="Button" />
</div>
</asp:Content>
<asp:Content ID="Content3" runat="server" ContentPlaceHolderID="cphSidebar">
<br />
<br />
<uc1:SelPessoas ID="SelPessoas1" runat="server" />
<br />
<br />
</asp:Content>
<asp:Content ID="Content5" runat="server" ContentPlaceHolderID="ContentPlaceHolderMenuOptions">
<ig:WebDataMenu ID="WebDataMenuOptions" runat="server" Font-Bold="False" OnItemClick="WebDataMenuOptions_ItemClick">
<ItemSettings />
<Items>
<ig:DataMenuItem ImageUrl="~/img/refresh_16.png" Key="btnRefrescar" Text="Refrescar">
</ig:DataMenuItem>
</Items>
<GroupSettings Orientation="Horizontal" />
</ig:WebDataMenu>
</asp:Content>