Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2007, 12:27 PM
Authorized User
 
Join Date: Jun 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display current date and time in a webform TextBox

Hello,

How do you display the current date and time in a textbox on a webform? I have been using the below code, but receive error because is says the textbox is not delcared. I have the textbox plased on the InsertItmeTemplate of a webform.


 Protected Sub time_stamp_entryTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim dtNow As DateTime = DateTime.Now
        time_stamp_entryTextBox.Text = dtNow.ToString
    End Sub

 
Old October 22nd, 2007, 01:19 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First you could shorten this up a bit:
time_stamp_entryTextBox.Text = DateTime.Now.ToString()

Secondly, show us how you have declared your textbox.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
 
Old October 22nd, 2007, 02:16 PM
Authorized User
 
Join Date: Jun 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I have shortened the textbox to txtboxTimeEntry. Also, I have delceared the textbox by placing a textbox into the main Content Area, before the FormView Section. This is the only way that I know how to do this at the present time. I have read an article (http://www.eps-software.xn--comwww-y...0503051&page=1), but, I am still not 100% clear on how to declear the textbox within the FormView or DataGrid Section.

************************************************** *************
<%@ Page Language="VB" MasterPageFile="~/DefaultMembers.master" AutoEventWireup="false" CodeFile="subCustomer.aspx.vb" Inherits="MemberPages_subCustomer" title="Customer Profile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    <h4>
        Customer Profile<br />
    </h4>

<asp:TextBox ID="txtboxTimeEntry" runat="server" OnTextChanged="txtboxTimeEntry_TextChanged"
        Text='<%# Bind("time_stamp_entry") %>' Visible="False" Width="37px"></asp:TextBox>

<asp:FormView ID="FormView1" runat="server" DataKeyNames="CustomerID" DataSourceID="AccessCustomerProfile"
        DefaultMode="Insert" Width="566px" CellPadding="4" ForeColor="#333333">
         <InsertItemTemplate>


************************************************** ***************
    Protected Sub txtboxTimeEntry_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim dtNow As DateTime = DateTime.Now
        txtboxTimeEntry.Text = dtNow.ToString
    End Sub

 
Old October 22nd, 2007, 02:37 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First, to answer your original question, when you create a TextBox control inside of a FormView (or repeater, or gridview, etc) you aren't declaring the control in the scope that the page can see.

For example:
<asp:TextBox id="txt" runat="server" />
can be accessed like this:
txt.[property] = "foo"

However when you create a control INSIDE one of the aforementioned controls like this:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="CustomerID" DataSourceID="AccessCustomerProfile"
        DefaultMode="Insert" Width="566px" CellPadding="4" ForeColor="#333333">
         <InsertItemTemplate>
            <asp:TextBox id="txt" runat="server" />
         </InsertItemTemplate>

The control does not exsist UNTIL you have bound data to the control or the particular template is being viewed. This is why you are getting the error that you are because the control doesn't actually exsist.

You need to handle the event that will expose this control to you (I don't use the form view much so I am not sure which event you need to handle) then you can assign it the TextChanged property. Imar or Peter may be able to better guide you on this.



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
 
Old October 22nd, 2007, 04:07 PM
Authorized User
 
Join Date: Jun 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you DPARSONS for the update.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Display current time 'fast' on a form. jpool Visual Basic 2005 Basics 1 July 4th, 2008 01:39 PM
Current Date and Time in XSLT devMc XSLT 6 October 21st, 2007 04:49 AM
getting current date and time in xslt 1.0 ashyabhi_hp XSLT 1 September 24th, 2007 03:17 AM
Display the current record in textbox (form) Vassala Access 2 January 25th, 2007 05:05 PM
Current date time in XSLT verison 1.0 ksskumar XSLT 1 October 17th, 2006 07:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.