Click here to Skip to main content
15,894,273 members
Please Sign up or sign in to vote.
2.29/5 (4 votes)
See more:
By changing textbox to read-only at the designer setting as below, 
i am not getting value from the textbox in the code behind.

For date picker I have used ASP.NET AJAX 's Calendar extender that is attached to TextBox control. And in the  textbox I am not allowing the user to directly write any text, user should only select date from Calendar. 
For achieving this, if I make textbox read-only then at the server side textbox.text is returning  blank(empty).


<asp:TextBox ID="txtDOB" runat="server" CssClass="cntls txt txt-calender" MaxLength="10"
 AutoComplete="off" placeholder="dd-MM-yyyy" ReadOnly="True"></asp:TextBox>

<asp:FilteredTextBoxExtender ID="txtDOB_FilteredTextBoxExtender" runat="server" ValidChars="-/"
 FilterMode="ValidChars" FilterType="Custom,Numbers,LowercaseLetters,UppercaseLetters"
 TargetControlID="txtDOB">
 </asp:FilteredTextBoxExtender>

 <asp:CalendarExtender ID="ceDOB" runat="server" Format="dd-MM-yyyy" TargetControlID="txtDOB"
  PopupButtonID="txtDOB" ClearTime="true" />

 <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtFirstName" SetFocusOnError="true" Display="None" ErrorMessage="Enter Date of Birth" ValidationGroup="vgStud"></asp:RequiredFieldValidator>

<asp:ValidatorCalloutExtender ID="RequiredFieldValidator3_ValidatorCalloutExtender"
runat="server" TargetControlID="RequiredFieldValidator3">
 </asp:ValidatorCalloutExtender>
Posted

Do you disable it, or make it read-only. There are two ways to do that and one of them has this issue.

If I'm not mistaken the property Enable makes it read-only and grays it out. (and also returns null) and the option read-only only makes it just that. Graying it out must then be done manually.

(PS: could be vice versa, it's been a while)
 
Share this answer
 
Comments
[no name] 5-Sep-14 5:08am    
I want user to select from Calendar Extender only ... i dont want user to enter there manually
V. 5-Sep-14 5:12am    
yes, I realized that... ?
[no name] 5-Sep-14 5:12am    
do u have any solution for that
Hi - to prevent user input on textboxes try the following:


Add an imagebutton to you page(after the textbox):
ASP.NET
<asp:ImageButton ID="ibtnDOB" runat="server" ImageUrl="~/Images/btncalendar.png" Height="25" Width="23" AlternateText="Select A Date" />


Modify your Calendar control to use the image button:
ASP.NET
<asp:CalendarExtender ID="ceDOB" runat="server" Format="dd-MM-yyyy" TargetControlID="txtDOB"
 PopupButtonID="ibtnDOB" ClearTime="true" />


Change your textbox to:
ASP.NET
<asp:Textbox ID="txtDOB" runat="server" cssclass="cntls txt txt-calender" maxlength="10" AutoComplete="off" placeholder="dd-MM-yyyy" onfocus="this.blur();"></asp:Textbox>


Hope it helps.
 
Share this answer
 
v3
Comments
[no name] 5-Sep-14 5:28am    
Calendar not coming :(
hypermellow 5-Sep-14 5:36am    
The onblur() event must be preventing the calendar from displaying.
I've updated the solution to fix that.
[no name] 5-Sep-14 6:19am    
in page load what i have to add
hypermellow 5-Sep-14 6:32am    
If your using the code from my submitted solution, you should'nt have to add anything in page_load.

I previously posted about adding the textbox's onfocus attribute.
This can be done in the markup (like above, by adding onfocus="this.blur();" to the Textbox) or in a code behind event, like adding txtDOB.Attributes.Add("onfocus", "this.blur()"); in Page_Load().

... is your calendar and textbox working now?
Hello ,
Just Remove the Read Only FromThe Textbox and set
JavaScript
onfocus="this.blur();"

.I have a Requirement similar to this. I Tired it By setting onfocus="this.blur();". It worked for me.
I suggest you to add a ToolTip to textbox for User to get complete Understand.

Hope It Helps You.
 
Share this answer
 
Remove Read Only from textbox and use this onkeydown="javascript:return false"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900