Disable all mondays from date picker .ext - c#

I´m trying to disable of mondays from a date picker in ext.js, but no sure how to make it without implement an array. cuz an array limite the range & days, & i want to disable for ever.
aspx:
<ext:DatePicker ID="DPdate" runat="server" Format="d/m/y">
<DirectEvents>
<Select OnEvent="LoadTableByDate">
<EventMask Msg="Cargando
Disponiblidad de salas" ShowMask="true" />
<ExtraParams>
<ext:Parameter Value="Ext.Date.format(App.DPdate.getValue(), 'd/m/Y')" Mode="Raw" Name="DPpicker" />
</ExtraParams>
</Select>
</DirectEvents>
</ext:DatePicker>

You can use the DisabledDays setting to disable given week days:
<ext:DatePicker ID="DPdate" runat="server" Format="d/m/y" DisabledDays="1" />
Source: Ext.NET 4.2.1 API docs on the DatePicker component

ASPX
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender">
</asp:Calendar>
Code Behind
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e){
if (e.Day.Date.DayOfWeek == DayOfWeek.Monday){
e.Day.IsSelectable = false;
}
}

Related

display date in textbox from gridview/database in asp.net

I develop one web form by using ASP.net, I want to select the row and display that row data into web form but the date cannot display in the textbox of type DateTime, someone helps me to sort out this issue
ASP.Net Code
<div class="col-4">
<asp:Label ID="Label7" runat="server" Text="Birth Date"></asp:Label>
<asp:TextBox ID="txtBirthDate" runat="server" TextMode="Date"></asp:TextBox>
</br>
<asp:Button ID="btnSave" Text="Save" runat="server" OnClick="btnSave_Click" />
</div>
<div class="col-8">
<asp:GridView ID="studentGrid" runat="server"
DataKeyNames="Id"
OnSelectedIndexChanged="StudentGrid_SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
</Columns>
</asp:GridView>
</div>
c# Code
protected void StudentGrid_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
selId = Convert.ToInt16(studentGrid.SelectedDataKey[0]);
if (selId > 0)
{
using (var ctx = new dbTestEntities())
{
var oldObj = ctx.tblStudents.Find(selId);
if (oldObj != null)
{
txtBirthDate.Text = oldObj.BirthDate.ToString();
}
}
}
}
catch (Exception)
{
throw;
}
}
The data keys is always referenced by name.
So, from the grid it is
GridView1.DataKeys[5]["ID"]
(Get the 5th row datakey value of "ID")
In your case, you have the selected row, so you need this:
selId = Convert.ToInt16(studentGrid.SelectedDataKey["ID"]);
Date format of the textbox with TextMode="Date" is "yyyy/MM/dd" but it stores date with default time like 2021/25/09 12:00:00 AM so the date is fetched from database but not able to set to the textbox, So we need to set the proper format of date like
txtBirthDate.Text = String.Format("{0:yyyy/MM/dd}", oldObj.BirthDate);

Compare two dates in ASP calender

I am a noob at ASP, I am trying to take take a selected date from an ASP calendar and save that in a textbox or something that I can compare with the second selected date so that the second is larger. I'm not sure if it is possible while just using one calendar. I tried but do not know how to save the first date collection for comparison. I tried both ways but failed miserable. I did do a search but they are using javascript, or java and other languages I do not know.
What I want to do:
I am trying to take two separate inputted dates from user. when 1st date is inputted, store in something, then validate that the user selects a date after the 1st selected date. If not return error message
<asp:TextBox ID="response" runat="server" />
<asp:TextBox ID="caldate1" runat="server" />
<asp:TextBox ID="caldate2" runat="server" />
<asp:CompareValidator ID="calvalidae" runat="server" ControlToCompare="caldate1" ErrorMessage="Date should be later than first date" Type="Date" operator="GreaterThan" ValueToCompare="caldate2"></asp:CompareValidator>
<asp:Calendar ID="cal1" runat="server"></asp:Calendar>
<asp:Calendar ID="cal2" runat="server" SelectionMode="Day" OnSelectionChanged="cal1_SelectionChanged" ></asp:Calendar>
//serverside
protected void cal1_SelectionChanged(object sender, EventArgs e)
{
caldate1.Text = cal1.SelectedDate.ToShortDateString();
if (cal1.SelectedDate.Date > cal2.SelectedDate.Date)
{
caldate1.Text = "You selected ";
caldate1.Text += cal1.SelectedDate.ToShortDateString();
}
else
{
caldate1.Text = "Select a valid date";
}
}
If you just want to compare the dates in code behind do the below
Markup
<asp:CompareValidator ID="calvalidae" runat="server"
ControlToValidate ="caldate1" ValueToCompare="text" ControlToCompare="caldate2"
ErrorMessage="Date should be later than first date" Type="Date"
operator="GreaterThan" ></asp:CompareValidator><br/>
<asp:Calendar ID="cal1" runat="server" OnSelectionChanged="cal1_SelectionChanged1"></asp:Calendar><br/>
<asp:Calendar ID="cal2" runat="server" SelectionMode="Day" OnSelectionChanged="cal2_SelectionChanged" ></asp:Calendar><br/>
</div>
Code Behind
protected void cal1_SelectionChanged1(object sender, EventArgs e)
{
caldate1.Text = cal1.SelectedDate.ToShortDateString();
IsValidDate();
}
protected void cal2_SelectionChanged(object sender, EventArgs e)
{
caldate2.Text = cal2.SelectedDate.ToShortDateString();
IsValidDate();
}
private void IsValidDate()
{
response.Text = string.Empty;
if (cal1.SelectedDate > cal2.SelectedDate)
{
response.Text = "Date should be later than first date";
}
}

asp calendar : blocking off when navigating previous/ next month

i'm using asp calendar in my webpage, when i was clicking the previous month arrow its just showing that month and popping off. but if its month navigation it should display as per my requirement ? and its selection date it should pop off.
Below is my code :
<asp:Image ID="Image1" runat="server" Height="20px" ImageUrl="~/Images/calendar.GIF" Width="20px" onclick="displayCalendar()" />
<div id="datePicker"><asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" ></asp:Calendar></div>
function displayCalendar() {
var datePicker = document.getElementById('datePicker');
datePicker.style.display = 'block';
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
StartDate.Text = Calendar1.SelectedDate.ToString("d");
}
anyone's help will be appreciated .
thanks
Got my solution for this question.
OnsivibleMonthChanged="<function()>"
calendar control.
and defining the function to display the calendar.

I want the textbox AJAX Mask Edit Extender to change based on a radio button selection

I creating an ASP.net online application with C# background. I am also using AJAX MaskEditExtender. I'm pretty new to AJAX and don't know Javascript. What I need to do is have the textbox AJAX mask change based on the selection of the radio buttons.
In this example they are choosing salary or hourly. I need the salary to be "999,999" and the hourly to be "99.99".
<asp:TextBox ID="finalwage" runat="server" Width="80px">$</asp:TextBox>
<!-- Salary Mask -->
<asp:MaskedEditExtender
ID="MaskedEditExtender1"
runat="server"
TargetControlID="finalwage"
Mask="999,999"
MessageValidatorTip="true"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="None"
ErrorTooltipEnabled="true">
</asp:MaskedEditExtender>
<asp:MaskedEditValidator
ID="MaskedEditValidator1"
runat="server"
ControlExtender="MaskedEditExtender1"
IsValidEmpty="true"
MinimumValue="0"
MaximumValueMessage="Must enter a number"
ControlToValidate="finalwage" >
</asp:MaskedEditValidator>
<!-- Hourly Mask -->
<asp:MaskedEditExtender
ID="MaskedEditExtender2"
runat="server"
TargetControlID="finalwage"
Mask="99.99"
MessageValidatorTip="true"
MaskType="Number"
InputDirection="RightToLeft"
AcceptNegative="None"
ErrorTooltipEnabled="true">
</asp:MaskedEditExtender>
<asp:MaskedEditValidator
ID="MaskedEditValidator2"
runat="server"
ControlExtender="MaskedEditExtender1"
IsValidEmpty="true"
MinimumValue="0"
MaximumValueMessage="Must enter a number"
ControlToValidate="finalwage" >
</asp:MaskedEditValidator>
.......
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
AutoPostBack="true"
RepeatDirection="Horizontal"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Text="Hourly" Value="Hourly"
<asp:ListItem Text="Salary" Value="Salary" />
</asp:RadioButtonList>
Heres the C# code that I thought would work:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue = "Hourly")
{
MaskedEditExtender1.Mask = "99.99";
}
if (RadioButtonList1.SelectedValue == "Salary")
{
MaskedEditExtender1.Mask = "999,999";
}
}
Try to move the RadioButtonList1_SelectedIndexChanged code to Page_Init. I believe RadioButtonList1_SelectedIndexChanged is too late in the lifecycle process to change the mask.

Problem with usage of RadioButton in GridView in ASP.NET

<asp:TemplateField HeaderText="Select One">
<ItemTemplate>
<input name="MyRadioButton" type="radio" />
</ItemTemplate>
</asp:TemplateField>
aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow di in GridView1.Rows)
{
RadioButton rad = (RadioButton)di.FindControl("MyRadioButton");
//Giving Error:Object reference not set to an instance of an object.
if (rad.Checked&&rad!=null)
{
s = di.Cells[1].Text;
}
}
Response.Redirect("applicants.aspx?form=" +s);
}
I couldn't get the row which is selected in RadioButton. Can you help me with this please.
You can only use FindControl with server-side controls. Replace your <input> HTML element with an ASP.NET radio button, e.g:
<asp:RadioButton ID="MyRadioButton" runat="server" ... />
you have to use runat="server"
<input name="MyRadioButton" type="radio" runat="server" id="MyRadioButton" />
As already mentioned, add runat="server" and change order of conditions evaluated from if (rad.Checked&&rad!=null) to if (rad!=null && rad.Checked)
By the way it's not so easy to make radiobuttons in GridView column exclusive. Look at this link if you will stumble on problem: Adding a GridView Column of Radio Buttons

Categories