Ajax calendar not working - c#

I am using Ajax Calendar for date picker. when i click the calendar image the page will get postback but the calendar popup windows is not getting popup. How to resolve this problem?
Thanks in advance.
<asp:TextBox ID="txt_FromDate" runat="server" AutoPostBack="True"
ontextchanged="txt_FromDate_TextChanged>
</asp:TextBox>
<cc1:CalendarExtender ID="cal_FromDate" PopupButtonID="ibtnFromDate"
runat="server" TargetControlID="txt_FromDate"
Format="MM/dd/yyyy">
</cc1:CalendarExtender>
<asp:ImageButton ID="ibtnFromDate"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"
ImageAlign="Bottom" runat="server"/>

Try This:
<asp:TextBox ID="btn1" runat="server">
</asp:TextBox>
<asp:ImageButton ID="img1" runat="server"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"/>
<cc1:CalendarExtender ID="calendar1" runat="server" PopupButtonID="img1"
TargetControlID="btn1" Enabled="True">
</cc1:CalendarExtender>

<asp:TextBox ID="txtDOB" runat="server" Width="50%"></asp:TextBox>
<cc1:CalendarExtender ID="txtDOB_CalendarExtender" runat="server"
TargetControlID="txtDOB"
Format="MM/dd/yyyy" PopupButtonID="imgDate"
PopupPosition="BottomLeft">
</cc1:CalendarExtender>
<asp:Image ID="imgDate" AlternateText="Image Date"
ImageUrl="~/Images/Calendar.png" runat="server" />

try this,
<asp:TextBox ID="txt_from" placeholder="MM/DD/YYYY" runat="server"
AutoPostBack="True" ontextchanged="txt_from_TextChanged">
</asp:TextBox>
<cc1:CalendarExtender ID="txt_from_CalendarExtender" runat="server"
Format="MM/dd/yyyy" Enabled="True"
TargetControlID="txt_from">
</cc1:CalendarExtender>
no need to use image button for calendar.

You are just missing a Property of CalanderExtender PopupButtonID. try the following
<asp:TextBox ID="txt_FromDate" runat="server" AutoPostBack="True"
ontextchanged="txt_FromDate_TextChanged">
</asp:TextBox>
<asp:ImageButton ID="ibtnFromDate"
ImageUrl="~/_layouts/images/PayrollImages/calendar.gif"
ImageAlign="Bottom" runat="server"/>
<cc1:CalendarExtender ID="cal_FromDate" PopupButtonID="ibtnFromDate"
runat="server" PopupButtonID="ibtnFromDate"
TargetControlID="txt_FromDate" Format="MM/dd/yyyy">
</cc1:CalendarExtender>

Related

Editing database from front-end, asp.net c#

I'm able to update the database fine, but how do I get the current information extracted from the database into the Edit textboxes.
This is my current code:
<asp:ListView ID="ListView1" runat="server" DataSourceID="Details">
<ItemTemplate>
<div class="col-xs-11">
<asp:Label ID="passwordname" runat="server"
Text="Current Password:" />
<asp:Label ID="password" runat="server"
Text='<%# Eval("Password") %>' />
</ItemTemplate>
</asp:ListView>
<asp:TextBox ID="editpassword" runat="server"
placeholder='<%# Eval("Password") %>' Text="New Password">
</asp:TextBox>
How do I get the textbox editpassword to show the current password stored?
Did you try binding the Value of the asp:TextBox?
Also, instead of using Eval(), consider model binding.
<asp:ListView ID="ListView1" runat="server"
DataSourceID="Details" ItemType="MyNamespace.MyClass">
<asp:TextBox ID="editpassword" runat="server"
Value='<%# BindItem.Password %>' Text="New Password">
</asp:TextBox>
Setting up databind for a listview using c#

Required Field Validator not working properly in gridview

Required Field Validator not working properly in gridview
I work in ASP.NET c# and MySQL database.
I need to make the required field of this DropDownList on FooterTemplate, but Required Field Validator not working.
Why ?
My code:
<FooterTemplate>
<asp:ImageButton ID="imgbtnInsert" runat="server" CommandName="Insert" ImageUrl="/images/icon_2.gif"
ToolTip="Add" OnClientClick="return confirm('Confirm?');" />
</FooterTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtIDDTES" runat="server" CssClass="ddl_Class_new">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rtxtIDDTES" runat="server" ControlToValidate="txtIDDTES"
ErrorMessage="***" Text="*" Display="Dynamic" ValidationGroup="Validation1"
SetFocusOnError="true" EnableClientScript="true"></asp:RequiredFieldValidator>
</FooterTemplate>
<asp:ValidationSummary ID="Validation1" ValidationGroup="Validation1" runat="server" ShowMessageBox="true" />
Can you please help me figure out the problem?
Thanks in advance.
Try this :
<form id="form1" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummaryTop" runat="server" ShowMessageBox="true" ShowSummary="false" />
...
<FooterTemplate>
<asp:DropDownList ID="txtIDDTES" runat="server" CssClass="ddl_Class_new">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rtxtIDDTES" runat="server" ControlToValidate="txtIDDTES"
ErrorMessage="***" Text="*" Display="Dynamic"></asp:RequiredFieldValidator>
</FooterTemplate>

Get an object (FileUpload) from a CompleteWizardStep

I'm having difficulty trying to access an FileUpload on a event ButtonImagem_Click in the code behind in C# that is within a CompleteWizardStep on a CreateUserWizard.
Where is my code:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatedUser="CreateUserWizard1_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" Title="Criar conta">
<ContentTemplate>
<%--...--%>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server" ID="CompleteWizardStep1">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1" ErrorMessage=""></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1" ErrorMessage="Apenas são aceites imagens." ValidationExpression="(.*\.([Gg][Ii][Ff])|.*\.([Jj][Pp][Gg])|.*\.([Bb][Mm][Pp])|.*\.([pP][nN][gG])|.*\.([tT][iI][iI][fF])$)"></asp:RegularExpressionValidator>
<br /><asp:Button ID="ButtonImagem" runat="server" Text="Concluir" OnClick="ButtonImagem_Click" />
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
Found a solution, just needed to add ContentTemplateContainer like this:
FileUpload FileU = (FileUpload)CompleteWizardStep1.ContentTemplateContainer.FindControl("FileUpload1");

TextBox OnTextChanged / PostBack not working

My problem is that I can't seem to get my textbox to fire the OnTextChanged event. I also checked and it doesn't seem like it is doing an autopostback despite the fact that it is set to true.
Basically, I am trying to validate the text in the textbox and either enable or disable a button based on the validation status.
Here's my code:
<asp:Panel ID="panelAccessControl" runat="server" Visible="false">
<asp:Panel ID="panelAddMileageRate" runat="server" BorderWidth="2" >
<h2>Add Mileage Rate</h2>
<asp:ScriptManager ID="scriptManagerMileageRate" runat="server" />
<asp:UpdatePanel ID="updatePanelAddMileageRate" runat="server">
<ContentTemplate>
<p>
Purpose:
<asp:DropDownList ID="ddlAddPurpose" runat="server"
AutoPostBack="true" Width="200px"></asp:DropDownList>
<br />
Country:
<asp:DropDownList ID="ddlAddCountry" runat="server"
AutoPostBack="true" Width="200px" >
</asp:DropDownList>
<br />
Effective Date:
<asp:Calendar ID="calAddEffectiveDate" runat="server">
</asp:Calendar>
<br />
Mileage Rate:
<asp:TextBox ID="txtAddMileageRate" runat="server"
AutoPostBack="true" Width="200px"
CausesValidation="true"
ontextchanged="txtAddMileageRate_TextChanged">
</asp:TextBox>
<asp:RegularExpressionValidator
ID="validatorAddMileageRate"
ControlToValidate="txtAddMileageRate" runat="server"
SetFocusOnError="true"
ErrorMessage="Only Numbers allowed"
ValidationExpression="^\d{1,20}(\.\d{0,4})?$">
</asp:RegularExpressionValidator>
</p>
</ContentTemplate>
</asp:UpdatePanel>
<p>
<asp:Button ID="buttonAddSecurityGroup" runat="server"
Text="Submit" onclick="buttonAddSecurityGroup_Click" />
</p>
</asp:Panel>
<asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
</asp:Panel>
The text box in question is txtAddMileageRate.
Set the EventName property for your txtAddMileageRate AsyncPostBackTrigger to TextChanged.
Add following codes inside your update panel and outside of ContentTemplate
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtAddMileageRate"
EventName="TextChanged" />
</Triggers>
Other sugguestion:
Have you tried looking at the AutoComplete (http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete) control that is part of the AjaxControlToolKit? Its behaves the same way you want your solution to behave.

Calendar control in asp.net c#

I need to add a calendar control with its associated buttons in asp.net with C#.
I have the code as below.
<asp:TextBox ID="txtDateFrom" CssClass="text-small" runat="server"
BorderWidth="1px" ToolTip="Click to choose date"></asp:TextBox>
<asp:Label ID="lblFromError" CssClass="Error" runat="server"
Text="*" Visible="False"></asp:Label>
<asp:Label ID="lblTo" runat="server" Text="To" ForeColor="Black"></asp:Label>
<asp:CalendarExtender ID="txtDateFrom_CalendarExtender" runat="server"
TargetControlID="txtDateFrom"
Format="yyyy-MM-dd" TodaysDateFormat="yyyy d, MMMM">
</asp:CalendarExtender>
You will need to add an ImageButton and set the CalendarExtender's PopupButtonID property to the ID of the ImageButton.
This is from the AjaxControlToolkit's sample web site:
<ajaxToolkit:ToolkitScriptManager runat="Server" ID="ScriptManager1" />
<b>Calendar with an associated button:</b><br />
<asp:TextBox runat="server" ID="Date5" />
<asp:ImageButton runat="Server" ID="Image1"
ImageUrl="~/images/Calendar_scheduleHS.png"
AlternateText="Click to show calendar" /><br />
<ajaxToolkit:CalendarExtender ID="calendarButtonExtender" runat="server"
TargetControlID="Date5" PopupButtonID="Image1" />
you can use the JQuery plugin for Calendar. Check this topic
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>
<div type="text" id="datepicker"></div>
Do like this
1. Add a ToolkitScriptManager
2. Add a TextBox Control
3. Add a CalendarExtender
Here is the complete code :
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<asp:CalendarExtender
ID="CalendarExtender1"
TargetControlID="txtStartDate"
runat="server" />

Categories

Resources