Professional Web Applications Themes

Setting Default Date - ASP.NET General

I'd like to have a text box on my webform and a button beside that will set the current date in the text box when the button is clicked. Is there a way to do this without doing a postback? Thanks for your help. Jeff...

Sponsored Links
  1. #1

    Default Setting Default Date

    I'd like to have a text box on my webform and a button beside that will set
    the current date in the text box when the button is clicked. Is there a way
    to do this without doing a postback?

    Thanks for your help.
    Jeff


    Sponsored Links
    Jeff Guest

  2. #2

    Default Re: Setting Default Date

    Hi Jeff,

    You could use a little client-side JavaScript attached to the server-side
    button (show below). By including 'return false', you avoid the postback. For
    variations on the formatting of the date, look here
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsobjdate.asp
    or in any good JavaScript site.

    Does this help?

    Ken
    MVP [ASP.NET]

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    Button1.Attributes.Add _
    ("onclick", "var theDate=new Date();" & _
    "doent.forms[0].txtDate.value=theDate;return false;")
    End Sub


    <form id="Form1" method="post" runat="server">
    <asp:textbox id="txtDate" runat="server"></asp:textbox>
    <asp:button id="Button1" runat="server" text="Default"></asp:button>
    </form>


    --
    Microsoft MVPs have a question for *you*: Are you patched against the Worm?
    http://www.microsoft.com/security/security_bulletins/ms03-026.asp



    "Jeff Cope" <com> wrote in message
    news:%phx.gbl...
    I'd like to have a text box on my webform and a button beside that will set
    the current date in the text box when the button is clicked. Is there a way
    to do this without doing a postback?

    Thanks for your help.
    Jeff



    Ken Guest

  3. #3

    Default Re: Setting Default Date

    java script
    var today = new Date();
    onclick = "txtbox1.value= today.toDateString();"
    or
    many other possibilities
    today.getMonth();
    today.getDay();
    today.getYear();
    today.getFullYear();
    concatinate to get month/day/year

    "Jeff Cope" <com> wrote in message
    news:%phx.gbl... 
    set 
    way 


    MS Guest

  4. #4

    Default Re: Setting Default Date


    "Ken Cox [Microsoft MVP]" <ca> wrote in message
    news:phx.gbl... 
    For 
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsobjdate.asp 

    Yes that's what I was looking for...Thanks for your help.


    Jeff Guest

  5. #5

    Default Re: Setting Default Date

    Thanks for your help...


    Jeff Guest

Similar Threads

  1. Setting the Default Application.
    By TOC@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: November 8th, 06:31 PM
  2. Replies: 4
    Last Post: April 9th, 05:53 PM
  3. Setting Default Font
    By James in forum Macromedia Director Basics
    Replies: 0
    Last Post: July 6th, 09:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139