AjaxToolKit CalendarExtender Problems - c#

In my Summary page, I have two CalendarExtender controls to enable someone to select Start Date and End Date for database queries.
In the head of my Summary.aspx page, I have the following declarations:
<%# MasterType VirtualPath="~/Site.Master" %>
<%# Page Title="ACP Sheet Metal - Summary" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Summary.aspx.cs" Inherits="AcpSheetMetal.Summary" UICulture="es" Culture="es-MX" %>
<% #Import Namespace="System.Globalization" %>
<%# Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
For the page itself, I have a ToolkitScriptManager, two (2) TextBox controls, two CalendarExtender controls, and a GridView control:
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" />
<asp:TextBox ID="txtStartDate" runat="server" />
<asp:CalendarExtender ID="calExStartDate" runat="server" TargetControlID="txtStartDate" OnClientShown="ChangeCalendarView" OnClientDateSelectionChanged="checkDate" />
<asp:TextBox ID="txtEndDate" runat="server" />
<asp:CalendarExtender ID="calExEndDate" runat="server" TargetControlID="txtEndDate" OnClientShown="ChangeCalendarView" OnClientDateSelectionChanged="checkDate" DaysModeTitleFormat="MM/dd/yyyy" DefaultView="Months" Enabled="True" TodaysDateFormat="MMMM dd, yyyy" />
<asp:GridView ID="summaryGridView" runat="server" />
In the Page_Load event in the C# code, I have placed the following:
protected void Page_Load(object sender, EventArgs e) {
MasterPage = (SiteMaster)Page.Master;
if (!Page.IsPostBack) {
calExEndDate.TodaysDateFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
calExStartDate.TodaysDateFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
}
}
So, why are my Calendar controls not working? There are no values in the calendars and the language appears to be Spanish.

Just add EnableScriptGlobalization="true" in your ScriptManager like this:

Your language is Spanish and I believe it's so because your UICulture is UICulture="es" (ESpañol) and Culture="es-MX" (Español México).
See this line on your markup:
<%# Page Title="ACP Sheet Metal - Summary" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Summary.aspx.cs" Inherits="AcpSheetMetal.Summary" UICulture="es" Culture="es-MX" %>
The rest of your markup looks okay to me.

Related

how to get data value from user control in parent class of c#

Control 1:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="cntrlIPSEntry.ascx.cs" inherits="ServiceManagement.Control.cntrlIPSEntry" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<asp:TextBox ID="txtModel" CssClass="form-control" runat="server"></asp:TextBox>
another control:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="CustomerInfo.ascx.cs" Inherits="ServiceManagement.Control.CustomerInfo" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<%# Register Src="~/Control/cntrlIPSEntry.ascx" TagPrefix="uc1" TagName="cntrlIPSEntry" %>
<asp:Button CssClass="btn btn-default" ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click"/>
in C# i want to catch control 1 data of txtModel
protected void btnSave_Click(object sender, EventArgs e)
{
//??
}
I think what you are looking for is FindControl. You first find the Control holding the TextBox in the Parent, in this case the Control with ID WebUserControl1. Then it's just a matter of finding the correct TextBox and cast it as one.
TextBox textBox = this.Parent.FindControl("WebUserControl1").FindControl("txtModel") as TextBox;
Label1.Text = textBox.Text;

Show a calendar extendar within Asp.net application

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.

the 'username' does not exist in the current context

I am making a Login Page with ASP.Net using C#... and i have put my html code in Login.aspx page . that contains a textbox named username but when I give reference of my textbox in Login.aspx.cs to make the validations on this text box ... as
if(string.IsNullOrEmpty(username.Text))
{
...
...
}
i am getting an error that is saying ...-"The 'username' doesn't exist in the current context"......
how can i get rid of this error .... it is making me mas .... Help will be appreciable towards this error ... please help me ....
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
It depends on what you have taken.
If you have draged and droped ASP TextBox the automatically code has generated as:
<asp:TextBox ID="username" runat="server"></asp:TextBox>
which automatically contains runat="server"
But if you have taken HTML text box then code is as follows:
<input id="username" type="text" />
In this you will have to add the line on your own as runat="server"
It will look as follows:
<input id="username" type="text" runat="server"/>
Then you can use it for serverside.
Hope its helpful.

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.

globalization not working in asp.net

I am trying to implement Globalization in my application but for some reason its not working
Please find the code below
Default.aspx
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="button1" meta:resourceKey="button1" runat="server" Text="" />
</asp:Content>
Default.aspx.cs
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("en");
Thread.CurrentThread.CurrentUICulture = new
CultureInfo("en-US");
base.InitializeCulture();
}
name of my resource file is Default.aspx.en-us.resx in "App_LocalResources" folder
it carries only one key
key-->button1.Text
value--> Save
Please advice
I followed your instructions and got the same results as you, except for the error. The problem I found was that unless there is a default resource file then the language specific one does not work for some reason.
So I made a copy of the default.aspx.en-us.resx, and named it default.aspx.resx in the same directory, and then made sure that the default.aspx.en-us.resx had a different value than the default and it worked.

Categories