By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

runat="server"....a simple html textbox or a webform server textbox...that is the question.

P: n/a
I just realized that the code I inherited is using all asp.net server
controls (ie. webform controls) and when I try to update textboxes on the
client side, I lose the new value of the textbox when submitting the form to
update the database. The server doesn't have the client side value any more.

It seems to me that as I begin to write the client side javacript code for
form validation and client side editing capabilities in order to save round
trips to the server, I should change all these "data entry" controls, at
least the humble textbox...to a simple html control.

Can I just simply remove the ' runat="server" ' statement at the beginning
of the textbox control along with removing the asp: from the <asp:textbox
statement ?

Do I want to do this? I know I can answer my own question partially by
saying that I want to initially populate my textbox from the server side
when I initially load my page with database values. After that however, I
would like to not be bound by the server for this control in that state that
Kevin Spencer so correctly once referred to as that point at which "The
server and client are irreparably separated" I hope I didn't take that out
of context for Kevin.

I know I have used Request.Form in the past to pass along values to the
server but that seems to get me back into that round trip way of doing
business. I can see the value of passing a value back to the server if it is
used for a test condition, the result being used to generate an altered
client page, but it seems that in general for just changing the value of say
"company name" or "address", then just hanging an html textbox out there is
all I want for this.

It sounds like my question is when to use the straight html textbox and when
to use the server control textbox. And I am willing to admit that I should
know the answer to that question but I honestly flat out do not.

Thanks for your advice, explanations, or opinions.

Greg Hazzard
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

if you set the control value in the page load and donít protect against
re-assignment while post back happened the value will be restore to the
one set in the page_load any way. If you donít set any value to the
control it will hold data if entered by user or by javascript. I add a
sample code[1].

For your question, when I start using (checking) ASP.NET I use the
server controls as much as I can. I was fascinated from the web controls
event model. But as the time moves on and I start to test application
for performance and network pressure I found out that there are "SOME"
problems with web controls. The model event force post back to the
client. To simulate a single page filling add the annoying view state
that hurt network connection with low bandwidth. Now days I try to use
HTML control as much as I can. if I create page without any post back
events (like date selection modal form, or any modal form that return
value to the calling page) Iím not using web controls.

[1] -
Code behind:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

}
private void Button1_Click(object sender, System.EventArgs e)
{
String s = this.TextBox1.Text;
}

HTML :
<HTML>
<HEAD>
<title>WebForm3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script id="clientEventHandlersJS" language="javascript">
<!--

function nat_onclick() {
document.all["TextBox1"].value = "natty";
}

//-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm3" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 205px;
POSITION: absolute; TOP: 103px" runat="server" Width="146px"
Height="63px"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 187px; POSITION:
absolute; TOP: 200px" runat="server" Width="36px" Height="21px"
Text="Button"></asp:Button>
<INPUT id="nat" name="nat" style="Z-INDEX: 103; LEFT: 402px; WIDTH:
62px; POSITION: absolute; TOP: 112px; HEIGHT: 19px" type="button"
value="Button" language="javascript" onclick="return nat_onclick()">
</form>
</body>
</HTML>

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2

P: n/a
Hi Greg,

I am glad to hear it. Please post here if there are any more questions. Thanks very much for participating the community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

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

--------------------
!From: "Hazzard" <ha**@sonic.net>
!References: <Ow**************@tk2msftngp13.phx.gbl> <uM**************@TK2MSFTNGP12.phx.gbl>
<OX**************@tk2msftngp13.phx.gbl> <Nz**************@cpmsftngxa06.phx.gbl>
!Subject: Re: runat="server"....a simple html textbox or a webform server textbox...that is the question.
!Date: Mon, 21 Jul 2003 20:27:40 -0700
!Lines: 305
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <OC**************@TK2MSFTNGP11.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: dial-209-148-114-18.sonic.net 209.148.114.18
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:160887
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Thank you YanHong.
!I actually found out I left out a test for Ispostback and my code was taking
!an unintended path. My database edit functionality is working great now
!using the Microsoft Data Access Application Block.
!I still have some Javascript validation to carve into the presentation layer
!but using asp.net with FrontPage 2003, I have an application that I really
!like the looks of right now. The FrontPage html that is generated is clean
!and the themes are easily integrated with asp.net. I am not really going to
!worry about the resources used by the controls coming out of the
!System.Web.UI.WebControl namespace.
!
!With a PocketPC proof of concept yet to do, a web service to develop, some
!kind of XML Cursor API to demo....I am not too worried about a few extra
!calories at this point.
!
!All the best,
!Greg Hazzard
!Sebastopol, CA
!
!
!
!"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> wrote in message
!news:Nz**************@cpmsftngxa06.phx.gbl...
!> Hello Greg,
!>
!> By the way, if you create HtmlControls dynamically in the codebehind they
!will still have to be processed on the server to
!> create the Html. In fact even if they are in the aspx page they still
!have a small amount of overhead since the server still
!> creates an object for each Html element with a runat=server property. You
!are right that WebControls do use far more
!> resources though.
!>
!> Here are the naming conventions we use for the .NET Framework
!documentation:
!>
!>
!>
!>
!> Control
!>
!> Description
!>
!>
!> ASP+ server control
!>
!> Do not use. Use Web server control.
!>
!> Note If referring to the superset of server controls, use ASP.NET server
!control.
!>
!>
!> ASP.NET server control
!>
!>
!>
!> A control on an ASP.NET page. An ASP.NET server control has a runat=server
!attribute on a page. ASP.NET server
!> controls comprise a superset that includes Web server controls, HTML
!server controls, mobile controls, and so on.
!>
!>
!> custom control
!>
!>
!>
!> A control authored by a user or a third-party software vendor that does
!not belong to the .NET Framework class library. The
!> term custom control is a generic term. For specific contexts, use the
!following qualifiers:
!>
!> custom server control: a control used with ASP.NET pages.
!>
!> custom client control: a control used with Windows Forms.
!>
!>
!> HTML control
!>
!> Do not use. Use HTML server control.
!>
!>
!> HTML server control
!>
!> A control that appears as an HTML element marked by a runat=server
!attribute on an ASP.NET page. In contrast to Web
!> server controls, HTML server controls do not have an <asp:xxx> tag prefix.
!An HTML server control belongs to the
!> System.Web.UI.HtmlControls namespace.
!>
!>
!> server control
!>
!> Abbreviated form of ASP.NET server control. Use ASP.NET server control in
!the first mention in a topic and server control
!> thereafter.
!>
!>
!> server HTML control
!>
!> Do not use. Use HTML server control.
!>
!>
!> user control
!>
!> In ASP.NET: A user-authored server control that is developed as an ASP.NET
!page and saved as a text file with an .ascx
!> extension. The ASP.NET page framework compiles a user control on the fly
!to a class that derives from
!> System.Web.UI.UserControl.
!>
!> In Windows Forms: A user-authored client-side control that is developed by
!combining existing controls. A Windows Forms
!> user control is a class that derives from System.WinForms.UserControl.
!>
!>
!> Web control
!>
!> Do not use. If referring to a control that belongs to the
!System.Web.UI.WebControls namespace, use Web server control.
!> Otherwise use ASP.NET server control.
!>
!>
!> Web Forms control
!>
!> Do not use. If referring to the superset of server controls, use ASP.NET
!server control. Otherwise use a specific category
!> such as Web server control or HTML server control.
!>
!>
!> Web server control
!>
!> A control that has an <asp:xxxx> prefix on an ASP.NET page. A Web server
!control belongs to the
!> System.Web.UI.WebControls namespace.
!>
!> Hope it helps.
!>
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! - www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!>
!> --------------------
!> !From: "Hazzard" <ha**@sonic.net>
!> !References: <Ow**************@tk2msftngp13.phx.gbl>
!<uM**************@TK2MSFTNGP12.phx.gbl>
!> !Subject: Re: runat="server"....a simple html textbox or a webform server
!textbox...that is the question.
!> !Date: Sun, 20 Jul 2003 05:19:14 -0700
!> !Lines: 124
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!> !Message-ID: <OX**************@tk2msftngp13.phx.gbl>
!> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !NNTP-Posting-Host: dial-209-148-114-239.sonic.net 209.148.114.239
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl
!microsoft.public.dotnet.framework.aspnet:160564
!> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !
!> !Thank you once again Natty. It just occurred to me that I do have mentors
!in
!> !software development. Felix Wu has also been very helpful and so many
!> !others.
!> !
!> !I ran the code you supplied. Good basic exercise. I am digesting this. I
!> !think it demonstrates well the difference between client side button
!> !invocations and a server side round trip.
!> !
!> !You mentioned the view state. I was working on a project where a Sybase
!> !solution used something called an HTMLDatawindow. It also used a
!mechanism
!> !that I think is similar to the viewstate. I am still learning here so I
!want
!> !to reserve my own judgement but one thing the HTMLDatawindow did that I
!am
!> !glad the ASP.NET doesn't do is add a bunch of additional overhead for
!client
!> !side validation, etc. Without trying to explain further, a basic
!> !HTMLDatawindow page that was sent to the client weighed in with at least
!> !100K of code as I recall. Some very basic pages served up 300K. On 56K
!dial
!> !up modem connections this app was as slower than cold honey. Without
!> !wanting to try to carry this comparison or explanation any further, the
!> !point is that overhead with any system can clog the bandwidth. And then
!> !there is the complication factor.
!> !
!> !I think the value of your reply Natty is that I am seeing the value in
!> !trying to keep my solution as 'clean' as possible without loading it up
!with
!> !controls I don't need and in some cases I don't want. If I don't
!understand
!> !them, that is even worse.
!> !
!> !At least the issue of web controls and viewstate is an order of magnitude
!> !easier to deal with than the Design Time Controls (DTC's) that existed in
!> !Visual Interdev. Those were, as the particular Sybase technology I
!> !mentioned, 'controls on steroids'. They looked good in the beginning but
!had
!> !serious side effects.
!> !
!> !Appreciatively,
!> !
!> !Greg Hazzard
!> !Sebastopol CA
!> !
!> !
!> !
!> !
!> !"Natty Gur" <na***@dao2com.com> wrote in message
!> !news:uM**************@TK2MSFTNGP12.phx.gbl...
!> !> Hi,
!> !>
!> !> if you set the control value in the page load and don't protect against
!> !> re-assignment while post back happened the value will be restore to the
!> !> one set in the page_load any way. If you don't set any value to the
!> !> control it will hold data if entered by user or by javascript. I add a
!> !> sample code[1].
!> !>
!> !> For your question, when I start using (checking) ASP.NET I use the
!> !> server controls as much as I can. I was fascinated from the web
!controls
!> !> event model. But as the time moves on and I start to test application
!> !> for performance and network pressure I found out that there are "SOME"
!> !> problems with web controls. The model event force post back to the
!> !> client. To simulate a single page filling add the annoying view state
!> !> that hurt network connection with low bandwidth. Now days I try to use
!> !> HTML control as much as I can. if I create page without any post back
!> !> events (like date selection modal form, or any modal form that return
!> !> value to the calling page) I'm not using web controls.
!> !>
!> !> [1] -
!> !> Code behind:
!> !> private void Page_Load(object sender, System.EventArgs e)
!> !> {
!> !> // Put user code to initialize the page here
!> !>
!> !> }
!> !> private void Button1_Click(object sender, System.EventArgs e)
!> !> {
!> !> String s = this.TextBox1.Text;
!> !> }
!> !>
!> !> HTML :
!> !> <HTML>
!> !> <HEAD>
!> !> <title>WebForm3</title>
!> !> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
!> !> <meta name="CODE_LANGUAGE" Content="C#">
!> !> <meta name="vs_defaultClientScript" content="JavaScript">
!> !> <meta name="vs_targetSchema"
!> !> content="http://schemas.microsoft.com/intellisense/ie5">
!> !> <script id="clientEventHandlersJS" language="javascript">
!> !> <!--
!> !>
!> !> function nat_onclick() {
!> !> document.all["TextBox1"].value = "natty";
!> !> }
!> !>
!> !> //-->
!> !> </script>
!> !> </HEAD>
!> !> <body MS_POSITIONING="GridLayout">
!> !> <form id="WebForm3" method="post" runat="server">
!> !> <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 205px;
!> !> POSITION: absolute; TOP: 103px" runat="server" Width="146px"
!> !> Height="63px"></asp:TextBox>
!> !> <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 187px; POSITION:
!> !> absolute; TOP: 200px" runat="server" Width="36px" Height="21px"
!> !> Text="Button"></asp:Button>
!> !> <INPUT id="nat" name="nat" style="Z-INDEX: 103; LEFT: 402px; WIDTH:
!> !> 62px; POSITION: absolute; TOP: 112px; HEIGHT: 19px" type="button"
!> !> value="Button" language="javascript" onclick="return nat_onclick()">
!> !> </form>
!> !> </body>
!> !> </HTML>
!> !>
!> !> Natty Gur, CTO
!> !> Dao2Com Ltd.
!> !> 28th Baruch Hirsch st. Bnei-Brak
!> !> Israel , 51114
!> !>
!> !> Phone Numbers:
!> !> Office: +972-(0)3-5786668
!> !> Fax: +972-(0)3-5703475
!> !> Mobile: +972-(0)58-888377
!> !>
!> !> Know the overall picture
!> !>
!> !>
!> !> *** Sent via Developersdex http://www.developersdex.com ***
!> !> Don't just participate in USENET...get rewarded for it!
!> !
!> !
!> !
!>
!>
!
!
!
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.