In many cases we need to use read only text box so user cannot edit the value but readonly textbox will lost its value after postback. Let’s say you have a read only text box to set date by using ajax calendar so after post back date will be lost, other case might be you are setting some value in design view of aspx page which will lost after post back.
Suppose you have following HTML in your page
<asp:TextBox ID="text1" runat="server" Value="ABC" /> <asp:TextBox ID="text2" runat="server" Value="XYZ" ReadOnly="true"/>
After post back text2 will lost it's value, text2 values is posted back but will not populate a read-only textbox after postback, so how to keep text2 value even after postback, we can manually populate read only text box value by adding following line to Page_Load method
text2.Text = Request.Form[text2.UniqueID];
another easier way is to never use read only property at design time but add attribute from Page_Load method like this
Another problem with ReadOnly = true property setting at design time is that when you will try to set text box value from ajax calendar it will not set anything but by using
text2.Attributes.Add(“readonly”, “readonly”) you can easily set calendar selected date in text box.
Having 13+ years of experience in Microsoft Technologies (C#, ASP.Net, MVC and SQL Server). Worked with Metaoption LLC, for more than 9 years and still with the same company. Always ready to learn new technologies and tricks.
|By Ali Adravi On 24 Apr, 13 Viewed: 3,005|
Most of the times we need to use GridView control to show tabular data in our asp.net application. We simply write procedure to search the records and bind them with GridView and show 10 to 20 records per page. Have you ever thought that why you are fetching all the records and show only 10 to 20... By Ali Adravi On 16 Feb 2013 Viewed: 6,580
A nice feature with ASP.Net is the model binding, it reduced our code and effort to bind our well know controls like GridView, DataList, Repeater etc. So let’s see how we can bind our old controls in new and easy way. Let’s see how we bind the our grid before 4.5 1. We write the code to get... By Mike .Net On 17 Jan 2013 Viewed: 2,699
In asp.net there is not control to select multiple files and upload them once with progress bar, so we will use a small third party DLL to achieve this functionality. We will use Flajaxian FileUploader, you can download it from [http://www.flajaxian.com] We will create three different images... By Hamden On 12 Jul 2012 Viewed: 5,867
I was searching for select/deselect all checkboxes code into a gridview. I found most of them only provide to select and deselet all the checkboxes if any of the checkbox is unselected into grid the main checkbox is not affecting. I further try to search some useful code but could not found any... By Ali Adravi On 10 Jul 2012 Viewed: 4,459