473,695 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Putting value in asp:TextBox

Try to put in a TextBox next month's date in format (MMM yyyy). The following
does NOT work, why is that?

<!--When rendered, the texbox is blank, although the text in the round
bracket after the textbox is rendered correctly as (July, 2005)-->
<asp:TextBox id="MonthTextBo x"
runat="server"> <%=System.DateT ime.Now.ToStrin g("y")%></asp:TextBox>
(<%=System.Date Time.Now.ToStri ng("y")%>)

<!--Same again. defaultMonth is initialised as early as page_init (as
opposed to page_load makes no difference
the text in round bracket after the textbox is displayed correctly-->
<asp:TextBox id="MonthTextBo x"
runat="server"> <%=defaultMonth %></asp:TextBox> (<%=defaultMont h%>)
//OnInit method appended here for reference
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
DateTime nextMonth = System.DateTime .Now;
nextMonth = nextMonth.AddMo nths(1);
// Put user code to initialize the page here
//defaultMonth = nextMonth.ToStr ing("y");
defaultMonth= "abc";
InitializeCompo nent();
base.OnInit(e);
}

However, I can do:
<asp:TextBox id="MonthTextBo x" runat="server"> at least this
works</asp:TextBox> (<%=defaultMont h%>)

What is going on? Using ASP.NET 1.1 on IIS5.1/WinXP Pro SP1.
Nov 19 '05 #1
3 2118
Updating the Text property of the TextBox in page_load does the trick!

"Patrick" wrote:
Try to put in a TextBox next month's date in format (MMM yyyy). The following
does NOT work, why is that?

<!--When rendered, the texbox is blank, although the text in the round
bracket after the textbox is rendered correctly as (July, 2005)-->
<asp:TextBox id="MonthTextBo x"
runat="server"> <%=System.DateT ime.Now.ToStrin g("y")%></asp:TextBox>
(<%=System.Date Time.Now.ToStri ng("y")%>)

<!--Same again. defaultMonth is initialised as early as page_init (as
opposed to page_load makes no difference
the text in round bracket after the textbox is displayed correctly-->
<asp:TextBox id="MonthTextBo x"
runat="server"> <%=defaultMonth %></asp:TextBox> (<%=defaultMont h%>)
//OnInit method appended here for reference
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
DateTime nextMonth = System.DateTime .Now;
nextMonth = nextMonth.AddMo nths(1);
// Put user code to initialize the page here
//defaultMonth = nextMonth.ToStr ing("y");
defaultMonth= "abc";
InitializeCompo nent();
base.OnInit(e);
}

However, I can do:
<asp:TextBox id="MonthTextBo x" runat="server"> at least this
works</asp:TextBox> (<%=defaultMont h%>)

What is going on? Using ASP.NET 1.1 on IIS5.1/WinXP Pro SP1.

Nov 19 '05 #2
Hi Patrick,

Yes, as for the <% %> code block, they're included in asp.net for asp
compatiable purpose, and it can only be used in aspx template at the top
html content , in another word, we can only mix the <% %> code with normal
html content , but can not inject them into ASP.NET server control's
tag(like <asp:TextBox... .. ).

For ASP.NET Server Controls, we have the following means to
programmaticall y assign property values for them:

1. Use code to set value for Control's Properties in code behind , this is
what you've found.

2. Using the <%# %> databinding expression to bind value for asp.net
server control,

#Data Binding Expression Syntax
http://msdn.microsoft.com/library/en...abindingExpres
sionSyntax.asp? frame=true

For example, suppose we have the following control definitaion in aspx
template:

<asp:TextBox id="TextBox1" runat="server"
Text="<%# GetTextValue() %>"
</asp:TextBox>


GetTextValue() is a public/protected function defined in the page's
codebehind class, then, we can call

TextBox1.BataBi nd();

in Page_Load or any other sub functions which will make he <%# %>
databiding experssion in TextBox1 control get invoked and bind the value
returned from GetTextValue to the TextBox1. For detailed info , you can
have a look on the above MSDN reference or searching the web for some
further reference.

If there're anything else we can help, please feel free to post here.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3
Hi Steven

A related question I believe:

I am using a FormView, Insert Template. I have 3 textboxes which are
bound. I would like to use a default (static) value in one of the
textboxes.

Here's the (relevant) sample code:

<InsertItemTemp late>

Stamp: <asp:TextBox ID="StampTextBo x" runat="server"
Text='<%#Bind(" fldStamp") %>'></asp:TextBox><br />

Again, what I would like to do is assign a default/static text "Canada"
to this textbox and bind it to fldStamp

I am fairly new at this and would appreciate your assistance and some
sample code.

Thanks
Shiraz
is it possible to assign a default value to a textbox which is

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1393
by: Craig Buchanan | last post by:
I have an asp:textbox embedded in a repeater. I would like to default a value in the textbox, but when I try to use the format: <asp:textbox id="qty" runat="server"> <%# DataBinder.Eval(Container.DataItem,"Quantity") %> </asp:textbox> I get an error. Do I need to set the value in code?
1
12266
by: Ed West | last post by:
Hello, How can I put a textbox control into a cell of an asp:Table? I was not able to do it from the properties sheet, so I put it in via html tab, but now I can't select it from the Design tab (nor select it from the Properties tab on the right). Any ideas? <asp:Table id="Table1" runat="server"> <asp:TableRow> <asp:TableCell Text="Email:"></asp:TableCell>
0
1431
by: Luis Esteban Valencia | last post by:
am trying to databind within an asp:textbox control. I have tried many variations found here but nothing seems to work. It works fine if I use a regular HTML textbox input though. Here is what I have tried: <asp:textbox id='<%#DataBinder.Eval(Container.DataItem, "EmailID")%>' cssclass="textbox" runat="server"><%#DataBinder.Eval(Container.DataItem, "Email")%></asp:textbox> I get '<%# DataBinder.Eval(Container.DataItem,...
3
2375
by: Chris | last post by:
I am trying to use a calendar popup to populate a date in a textbox. I am using the example described in this article: http://aspnet.4guysfromrolla.com/articles/030202-1.aspx However, this article uses a regular HTML input box, and I need to use an ASP Web control textbox. When the latter is rendered in the browser, some extra stuff like _ctl0 is added to the name of the textbox. So the calendar can't find the box to populate it.
0
10528
by: datakix | last post by:
After 16 hours of frustration, I've managed to solve this problem for a project I'm working on. The 'trick' is set EnableViewState="False" for the asp:textbox inside the Repeater control. The problem is that by default the asp:textbox ViewState is True. This means that the textbox value is automatically preserved between postback (saved in the __VIEWSTATE hidden field and restored during a page postback).
1
2106
by: Imran Aziz | last post by:
Hello All, I have an option of search on my web page coded as under <p>Search Bookmarks: <asp:TextBox ID="txtSearch" runat="server" class="texta" ></asp:TextBox><asp:Button ID="btnSearch" runat="server" class="button" Text="go" OnClick="btnSearch_Click" UseSubmitBehavior="true" /></p>
11
7745
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
0
1613
by: CharlesA | last post by:
Hi folks, I'm using ASP.net 1.1 with C# I've got this kind of thing going <div class="row"> <label class="col1">Rm Name</label> <asp:textbox id="txtRM" runat="server" cssclass="col2" ReadOnly="True" EnableViewState="False"></asp:textbox> <label class="col3">Rm Phone</label> <asp:textbox id="txtRmPhone" runat="server" cssclass="col4" ReadOnly="True"
0
3495
by: sjickells | last post by:
Hi I am having a problem using asp:TextBox's in a transparent table. I have a background image on the page and a table in the middle of the page. I have set the background colour of the table to white the used CSS to set the opacity to 90 so that you can see the background image through the table. The problem I am having is with the textboxes in the transparent
0
8639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8999
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4586
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2279
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.