如何使用CalenderExtender在ContentPlaceHolder
本文关键字:ContentPlaceHolder CalenderExtender 何使用 | 更新日期: 2023-09-27 17:53:51
我在我的项目中使用CalenderExtender
在内容占位符和日历扩展程序是在UserControl
。此控件在正常aspx页面中工作,但当我在ContentPlaceHolder
中拖动此控件时,它不工作。实际上Calender
没有出现在textBox
下面是我的代码,我在我的项目中使用。
ASPX:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Calender1.ascx.cs" Inherits="Facultymanagement.Calender1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox ID="txtcalender" runat="server">
</asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="MM/dd/yyyy"
TargetControlID="txtcalender" PopupButtonID="txtcalender"></asp:CalendarExtender>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
后台代码:protected void Page_Load(object sender, EventArgs e)
{
if (CalendarExtender1.SelectedDate.ToString() != "")
{
txtcalender.Text = CalendarExtender1.SelectedDate.ToString();
}
}
public string TextBox1Value
{
get
{
return txtcalender.Text;
// return Convert.ToString(Calendar.SelectedDate);
}
set { txtcalender.Text = value; }
}
}
这是我试图访问值的地方:
protected void Button1_Click1(object sender, EventArgs e)
{
Label1.Text = calender1.TextBox1Value.ToString();
}
你需要先找到控件
ContentPlaceHolder mpContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("ContentPlacename");
if (mpContentPlaceHolder1 != null)
{
Button btn_searsh;
btn_searsh = (Button)mpContentPlaceHolder1.FindControl("main_search");
btn_searsh.CssClass += " " + "btn-primary";//to pass the rentpage class
}
我想你一定是做错了什么。
下面的代码可以工作:WebUserControl1.ascx:
<%@ Control Language="C#" ClassName="WebUserControl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<script runat="server">
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" />
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" PopupButtonID="Image1">
</cc1:CalendarExtender>
default . aspx:
<%@ Page Language="C#" %>
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
<uc1:WebUserControl ID="WebUserControl2" runat="server" />
<uc1:WebUserControl ID="WebUserControl3" runat="server" />
<uc1:WebUserControl ID="WebUserControl4" runat="server" />
</form>
</body>
</html>