Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem of text box reset

Status
Not open for further replies.

Crazyec

Programmer
Joined
Aug 28, 2001
Messages
80
Location
HK
Dear Pros,
I have created a control page(.ascx) which has a drop down list box, two text boxes with a search button. The two text boxes are readonly which should be enter the date by a pop-up calendar.
User should select from the drop down list and the text boxes(date range) and click the search button. The grid view will refresh by the selected data.
(That's why I need to set the text boxes to be readonly in order to ensure the format of the date, to avoid the overflow error of the query)

After I enter the date range , choose the drop down list and click the search button, the date range text boxes are all reset to nothing while the drop down list still keep my selection. (My grid view is refresh without data too)

I think that is the problem of page_load that it create the text boxes again? but why the drop down list will not happen the same problem?

following is the code:
HTML:

Sub Page_Load(Sender As Object, E as EventArgs)
hlStartDate.NavigateUrl = "Javascript:pickDate('" & txtStartDate.ClientID & "')"
hlEndDate.NavigateUrl = "Javascript:pickDate('" & txtEndDate.ClientID & "')"
End Sub



Code:

<table>
<tbody>
<tr><td>
<asp:Label id="lblDate" runat="server" forecolor="Black" text="Date">Date:</asp:Label>&nbsp;
</td>
<td>
&nbsp;
<asp:HyperLink id="hlStartDate" runat="server" ImageUrl="Images\date-picker.gif"></asp:HyperLink>
&nbsp;
<asp:TextBox id="txtStartDate" runat="server" readonly="true" AutoPostBack="false"></asp:TextBox>
</td>
<td>
<asp:Label id="lblTo" runat="server" forecolor="Black" text="To">To</asp:Label>&nbsp;
</td>
<td>
&nbsp;
<asp:HyperLink id="hlEndDate" tabIndex="1" runat="server" ImageUrl="Images\date-picker.gif"></asp:HyperLink>
<asp:TextBox id="txtEndDate" runat="server" readonly="true" AutoPostBack="false"></asp:TextBox>
&nbsp;
<asp:button id="cmdSearch" tabIndex="3" runat="server" Text="Search"></asp:button>
<asp:Label id="label1" runat="server" forecolor="Black" text="label1">To</asp:Label>&nbsp; </td></tr> <tr><td>
<asp:Label id="lblUserID" runat="server" forecolor="Black" text="User ID">User ID:</asp:Label>&nbsp;
</td>
<td colspan="3">
&nbsp;
<asp:SqlDataSource id="UserDataSource" SelectCommand="SELECT * FROM tbl_user Order By user_ID" ConnectionString="<%$ ConnectionStrings:server1 %>" ProviderName="System.Data.SqlClient" Runat="server"></asp:SqlDataSource>
<asp:DropDownList id="UserList" tabIndex="2" runat="server" AutoPostBack="False" DataValueField="User_ID" DataTextField="User_Name" DataSourceID="UserDataSource"></asp:DropDownList>
</td></tr>
</tbody>
</table>


 
How are you populating the textboxes? Are you using javacript to write the values to them? If you are, I don't believe the values will be written to the viewstate, and that is why they are coming up blank on the post back.
If this is the case, you could always store the values to hidden fields on the form, and use those to repopulate the textboxes.


Jim
 
yes, I use javascript to write the value to them. But I see the values entered to the textboxes already.
And the point I don't understand is, when I change the readonly to be false, the text boxes will not reset to nothing.
 
when I change the readonly to be false, the text boxes will not reset to nothing.

Not sure what that means ...

When you change to readonly do you want to retain the values? Are you saying they are reset when you change the readonly property?

Jim
 
I change the readonly property to False. The textboxes are not reset after I press search button.

I want to retain the values after press search button.
 
Hi Jim,
may I know how to store the values to hidden fields on the form, and use those to repopulate the textboxes?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top