I used CalendarExtender with TextBox in aspnet.
<asp:TextBox ID="txtDateTime" TextMode="DateTime" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtDateTime" Format="G" Animated="True" PopupPosition="Right"
FirstDayOfWeek="Monday"></ajaxToolkit:CalendarExtender>
On Page_Load event I set current date and time to TextBox's value:
txtDateTime.Text = DateTime.Now.ToString();
Then, CalendarExtender doesn't work correctly. The calendar frame become completely white. Are you help me, what is the problem here?
<asp:TextBox runat="server" ID="txtDateTime" ValidationGroup="ModalPopup"></asp:TextBox>
<asp:CalendarExtender runat="server"
TargetControlID="txtDateTime"
PopupPosition="TopRight"
Format="dd/MM/yyyy HH:mm">
</asp:CalendarExtender>
<asp:MaskedEditExtender runat="server"
ID="meeDateTime"
TargetControlID="txtDateTime"
Mask="99/99/9999 99:99"
MaskType="DateTime"
UserDateFormat= "DayMonthYear"
UserTimeFormat="TwentyFourHour"
CultureDateFormat="DMY"
CultureDatePlaceholder="/" CultureTimePlaceholder=":">
</asp:MaskedEditExtender>
On Page Load use This code
protected void Page_Load(object sender, EventArgs e)
{
txtDateTime.Text = String.Format("{0:t}", Now);
}
Link below from stackoverflow
Display Current Date Time in TextBox using MaskedEditExtender in asp.net
You need to use a MaskedExtender too.
<asp:TextBox ID="TextBoxID" runat="server"/>
<ajaxToolkit:MaskedEditExtender ID="MaskData" runat="server" TargetControlID="TextBoxID" Mask="99/99/9999" MaskType="Date"/>
Then you can use the calendarExtender
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Enabled="True" TargetControlID="TextBoxID" Format="dd/MM/yyyy"/>
Related
I've been trying to fire the Checkbox OnCheckedChanged event of an ASPxCheckBox implemented in HeaderTemplate of code. But it isn't working.
Please find below code.
<dxwgv:GridViewDataTextColumn Caption="Select" FieldName="Included">
<Settings AllowAutoFilter="False" />
<HeaderTemplate>
<dxe:ASPxCheckBox ID="chkSelectAll" runat="server" AutoPostBack="True" AllowGrayed="false" OnCheckedChanged ="SelectAllOperation">
</dxe:ASPxCheckBox>
</HeaderTemplate>
<DataItemTemplate>
<dxe:ASPxCheckBox ID="chkSelect" runat="server" Value='<%# Eval("CompositeKey") %>'
Checked='<%# Eval("AccessCode").ToString() == "A" %>' OnInit="chkSelect_Init">
</dxe:ASPxCheckBox>
</DataItemTemplate>
<CellStyle HorizontalAlign="Center" />
</dxwgv:GridViewDataTextColumn>
Following is the function I expect to reach after checking the checkbox in HeaderTemplate.
public void SelectAllOperation(object sender, EventArgs e)
{
}
However, It is working fine when implemented in DataItemTemplate. When I select the checkbox in HeaderTemplate, OnCheckedChanged event is not fired and I'm unable to reach the required function.
I am using ajax calender extender to pickup date, but whenever I click on image button to popup calender, it is causing postback. I am doing as follows:
<asp:TextBox ID="txtDate" runat="server" ToolTip="Last Date" CssClass="g2"</asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" Height="26px" width="30px" ImageUrl="~/images/cal.jpg"></asp:ImageButton>
<asp:CalendarExtender ID="txtDate_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtDate" PopupButtonID ="ImageButton1"></asp:CalendarExtender>
I am confused, as I never encountered such scenerio before .
why don't you use it like this ,why are you using button for the calender extender.
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtStartDate" runat="server"/>
I'm using Visual Studio 2010 with framework 3.5 and Ajax Control Toolkit .NET 3.5.
I working on a asp.net web forms website.
On a form I have this: a textbox, an imagebutton, a button, a calendar and a requiredfieldvalidator:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
<br />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label id="Label3" runat="server">Date</asp:Label>
<asp:textbox id="txtInitialDate" runat="server" Width="75px" MaxLength="10"></asp:textbox>
<asp:ImageButton ID="imgBegin"
ImageUrl="~/images/Icon1.jpeg" runat="server"
AlternateText="" Height="24px" Width="24px" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtInitialDate"
PopupPosition="BottomLeft" PopupButtonID="imgBegin"
>
</asp:CalendarExtender>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtInitialDate"
Display="Dynamic"></asp:requiredfieldvalidator>
<asp:button id="Button2" runat="server" Text="Send" onclick="Button2_Click"></asp:button>
</asp:Content>
code behind:
override protected void OnInit(EventArgs e)
{
Button2.Attributes.Add("onclick", "javascript:" + Button2.ClientID + ".disabled=true;" + "javascript:" + Button2.ClientID + ".value='Processing.';" + this.GetPostBackEventReference(Button2) + ";");
base.OnInit(e);
}
protected void Button2_Click(object sender, EventArgs e)
{
string a = "some_value";
}
The interaction here is that the user clicks on the ImageButton, the calendar shows, the user clicks on a date and then hits the button.
The problem:
If I run the website and click on the ImageButton first and pick a date, then when the button is clicked no events are fired.
But if I comment the code of the validator:
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtInitialDate"
Display="Dynamic"></asp:requiredfieldvalidator>
Then the events are fired correctly.
I want to be able to use the requiredfieldvalidator, but I don't want it to create conflict with the button
Why is this happening and How can I solve this?
Thanks...
Use CausesValidation=False in the image button markup:
<asp:ImageButton ID="imgBegin" CausesValidation="False" ImageUrl="~/images/Icon1.jpeg" runat="server" Height="24px" Width="24px" />
You can add that javascript for Button2 in the markup also (instead of OnInit code-behind). Just use OnclientClick attribute in the Button2 mark up
Web.UI.Controls.TextBox
in my aspx page i have used-
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="tmaintextchanged" ></asp:TextBox>
in my code behind :
<asp:Label ID="show" runat="server" ></asp:Label >
protected void tmaintextchanged(object sender, EventArgs e)
{
show.Text = "working";
}
when I am executing this ,Why is the text of label "show" not changing.Kindly help. Am i missing any configuration to the Text box.
You need to set autopostback on TextBox control:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="tmaintextchanged" ></asp:TextBox>
Update
see this post:
How do I make a Textbox Postback on KeyUp?
<asp:TextBox ID="TextBox3" runat="server" Width="127px"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox3"
ErrorMessage="Must Be 8 characters"
onservervalidate="CustomValidator1_ServerValidate"
ValidateEmptyText="True"
ValidationGroup="g1">*</asp:CustomValidator>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="LogIn"
ValidationGroup="g1" Width="83px" />
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (args.Value.Length == 8)
{
args.IsValid = true;
}
else
args.IsValid = false;
}
I want textbox to take 8 characters.But the event is not getting fired up.I haved tried by taking Required Field Validator as well as ValidateEmptyText to true but either of them is not working
Please Help.
Try adding a RequiredFieldValidator for the TextBox too, and it should trigger the custom validator server validate event.
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox3"
ErrorMessage="Required">
</asp:RequiredFieldValidator>