We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How to set a default value in a text box

Medium Priority
930 Views
Last Modified: 2013-11-26
I have a gridview that looks to a textbox for the parameter to pass to my stored procedure in SQL.  I would like to have the textbox default when the page loads to yesterdays date so the gridview will run with yesterdays date as the parameter, but I also need to be able to re-run the stored procedure when the user changes the date in the textbox.  I don't know how to set the textbox to default to yesterdays date except for using the pageload event which obviously means I can only use yesterdays date because whatever date is typed in is just reset when the page reloads.  Can someone please help me with this?  I know very little about asp.net and visual studios.  
Comment
Watch Question

ok, here is an example
<!-- in the aspx page -->
<asp:TextBox ID="textbox1" runat="server" EnableViewState="true" />
// in the page load
If Not IsPostBack Then
   textbox1.Text = CStr(Format(Date.Now.AddDays(-1), "MM/dd/yyyy"))
End If
// If the user changes the date, it will hold the new date

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.