Show a calendar extendar within Asp.net application - c#

I have an Asp.net application in which i'd like to add a calendar extendar. So i use this code:
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Home.aspx.vb" Inherits="Home" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<cc1:ToolkitScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"></cc1:ToolkitScriptManager>
<span style=" margin-left: 60%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="error1" Text="error1" ControlToValidate="FirstDate" ForeColor="Red" Font-Bold="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="error2" Text="error2" ControlToValidate="FirstDate" ValidationExpression="^[0-3]+[0-9]\/[0-1]+[0-9]\/[0-9]{4}" ForeColor="Red" Font-Bold="true"></asp:RegularExpressionValidator>
<asp:TextBox ID="FirstDate" runat="server" ></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="FirstDate" CssClass="test">
</cc1:CalendarExtender>
</span>
</asp:Content>
The problem is : when i click into the TextBox the calendar isn't shown :
Why this happens?
How can i modify my code to fix this error?

I don't believe that the CalendarExtender behaves the way you're expecting. At least, it doesn't for me. What I usually do is add an ImageButton and make the CalendarExtender's PopupButtonID equal to the ImageButton's ID.

Related

fire a textbox's OnTextChanged while enabled=false

I have an ajax toolkit calendar extender attached to my textbox and i a trying to fire the OnTextChanged after the date was entered into the textbox.
The thing is i don't want the user to enter data manually so i disabled the textbox but the event won't fire for a disabled text box.
is there anyway around it? i thought about changing to a label but is doesn't have OnTextChanged event.
Thanks
<asp:TableCell CssClass="cssWidth" Width="150px">
<asp:CalendarExtender ID="CalendarExtender1" PopupButtonID="Image1" runat="server" TargetControlID="TextBoxAddDate" Format="dd/MM/yyyy"></asp:CalendarExtender>
<asp:TextBox ID="TextBoxAddDate" ReadOnly="true" CssClass="cssWidth" ToolTip="תאריך הוספה" runat="server" Style="font-size: large;background-color:aliceblue;" AutoPostBack="true" AutoCompleteType="Search" MaxLength="0" TextMode="SingleLine" OnTextChanged="txtSearch_TextChanged" ViewStateMode="Enabled" autocomplete="off" >
</asp:TextBox>&nbsp
<asp:ImageButton runat="Server" ID="Image1"
ImageUrl="~/Calendar_scheduleHS.png" AlternateText="Click to show calendar" /><br />
</asp:TableCell>
Can you use ReadOnly instead of Enabled = false?
UPDATE:
Ok, this is the complete solution that worked for me:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
function dateSelectionChanged(x) {
debugger;
javascript: __doPostBack('TextBoxAddDate', '')
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit www.asp.net.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CalendarExtender ID="CalendarExtender1" PopupButtonID="Image1" runat="server" TargetControlID="TextBoxAddDate" Format="dd/MM/yyyy" OnClientDateSelectionChanged="dateSelectionChanged" ></asp:CalendarExtender>
<asp:TextBox ID="TextBoxAddDate" CssClass="cssWidth" ToolTip="תאריך הוספה" runat="server" Style="font-size: large;background-color:aliceblue;" AutoCompleteType="Search" MaxLength="0" TextMode="SingleLine" OnTextChanged="txtSearch_TextChanged" ViewStateMode="Enabled">
</asp:TextBox>&nbsp
<asp:ImageButton runat="Server" ID="Image1"
ImageUrl="~/Calendar_scheduleHS.png" AlternateText="Click to show calendar" /><br />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
It seems that the CalendarExtender "steals" away the events from the texbox it uses.
Using this approach I managed to fire up the OnTextChanged event and the handler txtSearch_TextChanged gets executed.
Did you make the textbox ReadOnly?

Can't understand how to use DevExpress tab control

I can't get how to use DevExpress tab control. I dragged control and added three tabs, and when I try to put a content inside proper tags, it says that DevExpress.Web.ASPxTabControl.Tab doesn't have public property named div.
Here is the code:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AddNews.aspx.cs" Inherits="MarketingAdmin.EditNews" %>
<%# Register Assembly="DevExpress.Web.v12.1, Version=12.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxTabControl" TagPrefix="dx" %>
<%# Register Assembly="DevExpress.Web.ASPxEditors.v12.1, Version=12.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%# Register Assembly="DevExpress.Web.ASPxHtmlEditor.v12.1, Version=12.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxHtmlEditor" TagPrefix="dx" %>
<%# Register assembly="DevExpress.Web.ASPxSpellChecker.v12.1, Version=12.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxSpellChecker" tagprefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<dx:ASPxTabControl ID="ASPxTabControl1" runat="server" ActiveTabIndex="0"
EnableTheming="True" Theme="Glass">
<Tabs>
<dx:Tab Text="Казахский" >
<div style="font-family=Times New Roman; font-size:medium ">Категория
<asp:DropDownList ID="CategoryDropDownList" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="id" ></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MarketingConnectionString %>"
SelectCommand="SELECT [Name], [id] FROM [NewsCategory]"></asp:SqlDataSource>
</div>
<div style="font-family=Times New Roman; font-size:medium "> Заголовок
<asp:TextBox ID="TitleTextBox" runat="server" Width="610px"></asp:TextBox></div>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server">
</dx:ASPxHtmlEditor>
</dx:Tab>
<dx:Tab Text="Русский">
content 2
</dx:Tab>
<dx:Tab Text="Английский">
content 3
</dx:Tab>
</Tabs>
</dx:ASPxTabControl>
<asp:Button ID="SaveButton" runat="server" Text="Сохранить"
onclick="SaveButton_Click" />
</asp:Content>
Can anybody help me?
Based on what you're asking, I believe you need to use the ASPxPageControl. The ASPxTabControl is only to create a tabstrip with no actual "tabs" below the strip. It is best used for site navigation.

Error while deleting all child controls from the parent control

I have the next aspx page:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="newsEditor.aspx.cs" Inherits="ExpertSiteV2.newsEditor" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%# Register Assembly="ExpertSiteV2" Namespace="ExpertSiteV2" TagPrefix="custom" %>
<asp:Content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:Panel ID="Panel2" runat="server" Width="660" Style="margin-bottom: 10px;">
<asp:Label ID="Label1" runat="server" Text="Label" Width="150">Заголовок новости</asp:Label>
<asp:TextBox ID="newsTitle" runat="server" Width="500" Style="float: right;"></asp:TextBox>
</asp:Panel>
<custom:CustomEditor ID="Editor3" runat="server" Height="300" Width="660" BackColor="White" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Panel ID="Panel3" runat="server" Style="margin-top: 5px;" CssClass="buttonPanel">
<asp:ImageButton ID="SaveImageButton1" runat="server" ImageUrl="img/save_32.png"
ToolTip="Сохранить новость" />
<asp:LinkButton ID="SaveLinkButton1" runat="server" ToolTip="Сохранить новость">Сохранить</asp:LinkButton>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" ImageUrl="img/block_32.png"
PostBackUrl="news.aspx" ToolTip="Вернуться к странице новостей" />
<asp:LinkButton ID="LinkButton2" runat="server" ToolTip="Вернуться к странице новостей"
CausesValidation="False" PostBackUrl="news.aspx">Отмена</asp:LinkButton>
</asp:Panel>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Заголовок должен быть заполнен!"
ControlToValidate="newsTitle" Display="Dynamic">
</asp:RequiredFieldValidator>
</asp:Panel>
</asp:Content>
I want to delete all the contents of Panel1. I write the code:
Panel1.Controls.Clear();
But it doesn't work and I get the message:
Page cannot be null. Please ensure
that this operation is being performed
in the context of an ASP.NET request.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.InvalidOperationException: Page
cannot be null. Please ensure that
this operation is being performed in
the context of an ASP.NET request.
Source Error:
An unhandled exception was generated
during the execution of the current
web request. Information regarding the
origin and location of the exception
can be identified using the exception
stack trace below.
Stack Trace:
[InvalidOperationException: Page
cannot be null. Please ensure that
this operation is being performed in
the context of an ASP.NET request.]
System.Web.UI.ScriptManager.get_IPage()
+373832 System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object
sender, EventArgs e) +54
System.Web.UI.Page.OnPreRenderComplete(EventArgs
e) +8698462
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +1029
Blockquote
What's wrong? How should I do it properly?
Okay, i've written something like this:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="newsEditor.aspx.cs" Inherits="ExpertSiteV2.newsEditor" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%# Register Assembly="ExpertSiteV2" Namespace="ExpertSiteV2" TagPrefix="custom" %>
<asp:Content ID="Content3" ContentPlaceHolderID="Main" runat="server">
<asp:Panel ID="Panel4" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:Panel ID="Panel2" runat="server" Width="660" Style="margin-bottom: 10px;">
<asp:Label ID="Label1" runat="server" Text="Label" Width="150">Заголовок новости</asp:Label>
<asp:TextBox ID="newsTitle" runat="server" Width="500" Style="float: right;"></asp:TextBox>
</asp:Panel>
<custom:CustomEditor ID="Editor3" runat="server" Height="300" Width="660" BackColor="White" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Panel ID="Panel3" runat="server" Style="margin-top: 5px;" CssClass="buttonPanel">
<asp:ImageButton ID="SaveImageButton1" runat="server" ImageUrl="img/save_32.png"
ToolTip="Сохранить новость" />
<asp:LinkButton ID="SaveLinkButton1" runat="server" ToolTip="Сохранить новость">Сохранить</asp:LinkButton>
<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" ImageUrl="img/block_32.png"
PostBackUrl="news.aspx" ToolTip="Вернуться к странице новостей" />
<asp:LinkButton ID="LinkButton2" runat="server" ToolTip="Вернуться к странице новостей"
CausesValidation="False" PostBackUrl="news.aspx">Отмена</asp:LinkButton>
</asp:Panel>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Заголовок должен быть заполнен!"
ControlToValidate="newsTitle" Display="Dynamic">
</asp:RequiredFieldValidator>
</asp:Panel>
</asp:Panel>
</asp:Content>
Here is one more panel that contains everything. And I've written:
Panel4.Controls.Clear();
It works fine.
I still don't know why the Panel1 doesn't want to remove child controls. If someone knows just write the answer.
Can't you not just hide the panel? Panel1.Visible = false. why do you wanna remove the controls.
Aha ok I get the question now:
Check out this project, http://www.codeproject.com/KB/user-controls/DynamicUC.aspx

AJAX Firing OnUnload Twice

All, thanks in advance.
I'm using the ASP.NET AJAX Control Toolkit to create 2 CascadingDropDowns. The problem is the base OnUnload is firing twice when I load the page. Any idea how to stop this? See code snippets below.
Update: I've determined a workaround but if anyone knows of a way to suppress, I would be interested to hear!
<%# Page Language="C#" AutoEventWireup="true"
CodeFile="dataentry.aspx.cs"
Inherits="dataentry"
EnableEventValidation="false" %>
<ajaxToolkit:ToolkitScriptManager EnablePartialRendering="true"
runat="server"
ID="ScriptManager1" />
<asp:DropDownList ID="drpDate" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server"
TargetControlID="drpDate"
Category="Date"
PromptText="Please select a date"
ServicePath="SchedulerService.asmx"
ServiceMethod="GetSchedulerDates"
UseContextKey="true" />
<asp:DropDownList ID="drpTime" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server"
TargetControlID="drpTime"
ParentControlID="drpDate"
PromptText="Please select a time"
ServiceMethod="GetSchedulerTimesForDate"
ServicePath="SchedulerService.asmx"
Category="Time"
UseContextKey="true" />

Asp.net Ajax problem

I installed the Asp.net Ajax toolkit. In my site I use the NummericUpDown from that toolkit.
Now, I want that a label changes when the NummericUpDown Textboxes changes. I try to use JavaScript for this, but I always get the following error:
'ASP.orders_aspx' does not contain a definition for 'changeAmount' and no extension method 'changeAmount' accepting a first argument of type 'ASP.orders_aspx' could be found (are you missing a using directive or an assembly reference?)
This is my code:
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="orders.aspx.cs" Inherits="orders" Title="the BookStore" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
function changeAmount()
{
var amount = document.getElementById("txtCount");
var total = 10 * amount.value;
document.getElementById("lblPrice").value = total;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ScriptManager1" />
<h1 id="H1" runat="server">
Bestellen</h1>
<asp:Panel ID="pnlZoeken" runat="server" Visible="true">
<asp:ObjectDataSource ID="objdsSelectedBooks" runat="server" OnSelecting="objdsSelectedBooks_Selecting"
TypeName="DAL.BooksDAL"></asp:ObjectDataSource>
<h3>
Overzicht van het gekozen boek</h3>
<asp:FormView ID="fvBestelBoek" runat="server" Width="650">
<ItemTemplate>
<h3>
Aantal boeken bestellen</h3>
<table width="650">
<tr class="txtBox">
<td>
Boek
</td>
<td>
Prijs
</td>
<td>
Aantal
</td>
<td>
Korting
</td>
<td>
Totale Prijs
</td>
</tr>
<tr>
<td>
<%# Eval("TITLE") %>
</td>
<td>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("PRICE") %>' />
</td>
<td>
<asp:TextBox OnTextChanged="changeAmount()" ID="txtCount" runat="server"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender1" runat="server" TargetControlID="txtCount"
Width="50" Minimum="1" ServiceDownMethod="" ServiceUpMethod="" />
</td>
<td>
-
</td>
<td>
<asp:Label ID="lblAmount" runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:Button ID="btnBestel" runat="server" CssClass="btn" Text="Bestel" OnClick="btnBestel_Click1" />
<asp:Button ID="btnReChoose" runat="server" CssClass="btnDelete" Text="Kies een ander boek"
OnClick="btnRechoose_Click" />
</asp:Panel>
</asp:Content>
Does anyone know the answer?
Thanks a lot, Vincent
You're trying to assign a client-side method to the OnTextChanged event, which is a server-side event.
Also, your javascript is referencing the server id of the label and textbox. The WinForms engine appends characters to this depending where the control is nested. Use <%=myControl.ClientID%> to get around this.
You need to use some pure Javascript for this:
window.onload=function(){
//assign client method to textbox
document.getElementById('<%=txtCount.ClientID%>').onChange = function(){
var amount = document.getElementById('<%=txtCount.ClientID%>');
var total = 10 * amount.value;
document.getElementById('<%=lblPrice.ClientID%>').value = total;
}
}
Place that on your page instead of your current Javascript and get rid of the OnTextChanged="changeAmount()" attribute.
You set OnTextChanged for TextBox. It is refer to server method, that is fired on PostBack.
If you want to handle Up and Down events in background by method on your Page, you have to set
properties ServiceUpPath and ServiceUpMethod for NumericUpDown tag.
If you want to handle client events - set custom Up and Down buttons and set property OnClientClick to them.
See
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/NumericUpDown/NumericUpDown.aspx

Categories