How to set a default value in a text box

Posted on 2009-02-08
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 and visual studios.  
Question by:goffer
    1 Comment
    LVL 12

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now