将"重置"按钮设置为"用户控制"页中代码的默认值



用户控件中的此代码.ascx 页

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Dates.ascx.cs" Inherits="WebApplication3.Dates" %>
<b>Arivval Date: </b><br />  <br />
<asp:Calendar runat="server" ID="Arivval" ></asp:Calendar><br />
<b>Depart Date: </b> <br /> <br />
<asp:Calendar runat="server" ID="Depart" ></asp:Calendar>

和此代码在 Web 表单页面 (默认.ascx(

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HotelReservation.aspx.cs" Inherits="WebApplication3.HotelReservation" %>
<%@ Register TagPrefix="dt" TagName="Date" Src="~/Dates.ascx" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
<asp:Panel  runat="server" ID="ph">
<form id="form1" runat="server">
<asp:ImageButton ImageUrl="~/HotelImageButton.jpg"  ID="HOTEL" runat="server"  PostBackUrl="~/HotelReservation.aspx" />
<asp:ImageButton ImageUrl="~/CarImageButton.jpg"  ID="CAR" runat="server"  PostBackUrl="~/CarReservation.aspx" />
<h1 > Hotel Search </h1>
<dt:Date id="d" runat="server" />  <br />
<b>Nights:</b> <asp:TextBox id="num" runat="server" TextMode="Number" />
<br /> <br/>
<b> Room Type:</b> <br /> <br />
<asp:RadioButton id="Superior" runat="server" text="Superior" GroupName="RoomType" /> <br />
<asp:RadioButton id="Twin" runat="server" text="Twin" GroupName="RoomType" /> <br />
<asp:RadioButton id="Triple" runat="server" text="Triple" GroupName="RoomType" /> <br />
<asp:RadioButton id="DeLuxe" runat="server" text="DeLuxe" GroupName="RoomType" /> <br />
<asp:RadioButton id="Studio" runat="server" text="Studio" GroupName="RoomType" /> <br />
<br /> <br />
<asp:Button ID="search" Text="Search" runat="server" />
<asp:Button ID="Reset" Text="Reset"   runat="server" style="margin-left: 51px" Width="61px" OnClick="Clear" />

</form>
</asp:Panel>
</body>
</html>

在default.ascx.cs页面中,我想在用户控件中放置日历的重置按钮如何操作

protected void Clear(object sender, EventArgs e)
{
num.Text = "";
Boolean f = false;
Superior.Checked = f;
Twin.Checked = f;
Triple.Checked = f;
DeLuxe.Checked = f;
Studio.Checked = f;
}

我想输入 default.ascx.cs 在明文事件代码中,以使控件页面中的 2 个日历未被选中

为用户控件中的选定日期创建公共属性,并在宿主页中使用它们。像这样的东西。

<%@ Control Language="C#" ClassName="Dates" %>
<script runat="server">
public DateTime ArivvalDate
{
get { return Arivval.SelectedDate; }
set { Arivval.SelectedDate = value; }
}
public DateTime DepartureDate
{
get { return Depart.SelectedDate; }
set { Depart.SelectedDate = value; }
}
</script>
<b>Arivval Date: </b><br />  <br />
<asp:Calendar runat="server" ID="Arivval" ></asp:Calendar><br />
<b>Depart Date: </b> <br /> <br />
<asp:Calendar runat="server" ID="Depart" ></asp:Calendar>

页:

<!DOCTYPE html>
<%@ Page Language="C#" %>
<%@ Register Src="~/misc/Dates.ascx" TagPrefix="dt" TagName="Date" %>
<script runat="server">
protected void Clear(object sender, EventArgs e)
{
lstRoomType.SelectedIndex = -1;
d.ArivvalDate = DateTime.MinValue;
d.DepartureDate = DateTime.MinValue;
}
protected void search_Click(object sender, EventArgs e)
{
test.Text = string.Format("Arrival: {0:M/d/yy}, Departure: {1:M/d/yy}, Room Type: {2}", d.ArivvalDate, d.DepartureDate, lstRoomType.SelectedValue);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Reservation Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Hotel Search </h1>
<dt:Date ID="d" runat="server" />
<br />
<b>Nights:</b>
<asp:TextBox ID="num" runat="server" TextMode="Number" />
<br />
<br />
<b>Room Type:</b>
<br />
<br />
<%--use list instead of a set of individual RB --%>
<asp:RadioButtonList runat="server" ID="lstRoomType">
<asp:ListItem Text="Superior" Value="Superior" />
<asp:ListItem Text="Twin" Value="Twin" />
<asp:ListItem Text="Triple" Value="Triple" />
<asp:ListItem Text="Deluxe" Value="Deluxe" />
<asp:ListItem Text="Studio" Value="Studio" />
</asp:RadioButtonList>
<br />
<br />
<asp:Button ID="search" Text="Search" runat="server" OnClick="search_Click" />
<asp:Button ID="Reset" Text="Reset" runat="server" Style="margin-left: 51px" Width="61px" OnClick="Clear" />
<br />
<asp:Literal ID="test" runat="server" />
</div>
</form>
</body>
</html>

最新更新