如何创建在code-后面的日历? [英] How do I create a calendar in code-behind?
问题描述
我想创建一个asp.net阿贾克斯日历如这 ,但完全在code-后面。我该怎么做呢?
I want to create an asp.net ajax calendar like this, but entirely in code-behind. How do I do it?
编辑:我只是想给JS code添加到页面中的code-落后(如:没有标记)
I only want to add the js code to the page in code-behind (eg: not in the markup)
Edit_2:我需要这个,因为我创建一个模板类TextBox控件,并希望在那里创建日历(与文本框中使用)
Edit_2: I need this because I create a textbox control in a template class and want to create the calendar there (for use with the textbox)
推荐答案
你指的是ASP.NET AJAX的日历是一个扩展,因此在理论上,你可以在运行的时候在code-背后添加到您的文本框。请参见下面的实施例中,占位符是至关重要!
The ASP.NET ajax calendar you refer to is an extender, so in theory you could add it to your textbox at runtime in the code-behind. See the example below, the placeholder is vital!
我不知道你为什么会想这样做,你可以给我们的需要一个更好的主意,因为有可能是一个更好的解决方案。
I'm not sure why you would want to do this, can you give us a better idea of the need as there may be a better solution.
简单的页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<!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>
</head>
<body>
<form id="form1" runat="server"><asp:scriptmanager runat="server"></asp:scriptmanager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:PlaceHolder ID="Place1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
后面的 code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CalendarExtender myCalExt = new CalendarExtender();
myCalExt.TargetControlID = "TextBox1";
Place1.Controls.Add(myCalExt);
}
}
}
这篇关于如何创建在code-后面的日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!