473,772 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

textbox control

Hi There,

I am trying to display some textboxes on my page, When I run the code the
textbox is written to the page (when I view source) but not to the screen.
Could someone tell me if I have the syntax correct?
Sean - thanks in advance for your answer

!-- code
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.SqlClie nt" %>
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack then
BindData()
End If
End Sub
Sub BindData()
Dim dbRead As SqlDataReader
Dim strMFormControl as string
Dim strMFormValue as string
Dim strMDFormContro l as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(C onfigurationSet tings.AppSettin gs("connectionS tring"))

try
myConnection.Op en()
Dim myCommand As New SqlCommand("Get FormById", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure

dbRead = myCommand.Execu teReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormContro l = dbRead(4)
response.write ("<form runat=server><t able border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMFormContro l,strMFormValue )
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMDFormContr ol,strMDFormVal ue)

response.write ("</table></form>")

End While
dbRead.close

Catch oexpData As OleDb.OleDbExce ption
response.write ("an exception has occured,")
response.end
Finally
myConnection.cl ose
End Try

End Sub

!--- function here
Function DisplayFormItem (ByVal strMFormControl , ByRef strMFormValue)

Select Case Trim(strMFormCo ntrol)

Case "textbox"
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

Case "checkbox"

End Select

End Function

</script>


Nov 18 '05 #1
3 1432
Hi,

you can't write ASP.NET control declarations with Response.Write. Having
<asp:textBox> in page source is subject to compilation when the page is
first time requested. Response.Write writes the given string to the HTML
response, which is also generated/written by the compiled controls which
execute during Page's lifecycle. Using Response.Write does not cause
compilation to happen for controls(or this control on the Page). Compilation
is crucial thing in page processing and you, in fact, can't avoid it to get
things working.

You have three ways to declare controls:

a) Have them statically in aspx source
b) Create them dynamically in code and add to the Page's Controls
collection.
c) To create from markup at runtime, use Page.ParseContr ol(<control
declaration>) which returns a compiled control instance which you can place
to Page's Controls collection

But you can't output control declarations using Response.Write and assume
that they get compiled as fully-working controls.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"sean" <se**********@s hopsmart.com.au > wrote in message
news:eL******** ******@tk2msftn gp13.phx.gbl...
Hi There,

I am trying to display some textboxes on my page, When I run the code the
textbox is written to the page (when I view source) but not to the screen.
Could someone tell me if I have the syntax correct?
Sean - thanks in advance for your answer

!-- code
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.SqlClie nt" %>
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack then
BindData()
End If
End Sub
Sub BindData()
Dim dbRead As SqlDataReader
Dim strMFormControl as string
Dim strMFormValue as string
Dim strMDFormContro l as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(C onfigurationSet tings.AppSettin gs("connectionS tring"))

try
myConnection.Op en()
Dim myCommand As New SqlCommand("Get FormById", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure

dbRead = myCommand.Execu teReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormContro l = dbRead(4)
response.write ("<form runat=server><t able border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMFormContro l,strMFormValue )
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMDFormContr ol,strMDFormVal ue)

response.write ("</table></form>")

End While
dbRead.close

Catch oexpData As OleDb.OleDbExce ption
response.write ("an exception has occured,")
response.end
Finally
myConnection.cl ose
End Try

End Sub

!--- function here
Function DisplayFormItem (ByVal strMFormControl , ByRef strMFormValue)

Select Case Trim(strMFormCo ntrol)

Case "textbox"
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

Case "checkbox"

End Select

End Function

</script>

Nov 18 '05 #2
HI Teemu,

Thanks for your answer, it seems I am having a bit of troublemaking the
transition from asp to asp .net. Could you possibly help me out with a some
examples of two below? or give me a link to a website which illustrates the
examples that you have mentioned?

Sean

b) Create them dynamically in code and add to the Page's Controls
collection.
c) To create from markup at runtime, use Page.ParseContr ol(<control
declaration>) which returns a compiled control instance which you can place
to Page's Controls collection


"Teemu Keiski" <jo****@aspalli ance.com> wrote in message
news:OY******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

you can't write ASP.NET control declarations with Response.Write. Having
<asp:textBox> in page source is subject to compilation when the page is
first time requested. Response.Write writes the given string to the HTML
response, which is also generated/written by the compiled controls which
execute during Page's lifecycle. Using Response.Write does not cause
compilation to happen for controls(or this control on the Page). Compilation is crucial thing in page processing and you, in fact, can't avoid it to get things working.

You have three ways to declare controls:

a) Have them statically in aspx source
b) Create them dynamically in code and add to the Page's Controls
collection.
c) To create from markup at runtime, use Page.ParseContr ol(<control
declaration>) which returns a compiled control instance which you can place to Page's Controls collection

But you can't output control declarations using Response.Write and assume
that they get compiled as fully-working controls.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"sean" <se**********@s hopsmart.com.au > wrote in message
news:eL******** ******@tk2msftn gp13.phx.gbl...
Hi There,

I am trying to display some textboxes on my page, When I run the code the
textbox is written to the page (when I view source) but not to the screen.
Could someone tell me if I have the syntax correct?
Sean - thanks in advance for your answer

!-- code
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.SqlClie nt" %>
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack then
BindData()
End If
End Sub
Sub BindData()
Dim dbRead As SqlDataReader
Dim strMFormControl as string
Dim strMFormValue as string
Dim strMDFormContro l as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(C onfigurationSet tings.AppSettin gs("connectionS tring"))

try
myConnection.Op en()
Dim myCommand As New SqlCommand("Get FormById", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure

dbRead = myCommand.Execu teReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormContro l = dbRead(4)
response.write ("<form runat=server><t able border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMFormContro l,strMFormValue )
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMDFormContr ol,strMDFormVal ue)

response.write ("</table></form>")

End While
dbRead.close

Catch oexpData As OleDb.OleDbExce ption
response.write ("an exception has occured,")
response.end
Finally
myConnection.cl ose
End Try

End Sub

!--- function here
Function DisplayFormItem (ByVal strMFormControl , ByRef strMFormValue)

Select Case Trim(strMFormCo ntrol)

Case "textbox"
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

Case "checkbox"

End Select

End Function

</script>


Nov 18 '05 #3
I think you want to see the declarative way first.

http://www.dotnetjunkies.com/quickst...ormsintro.aspx

If you create a TextBox at runtime, it happens something like this:

Dim tb As New TextBox
tb.ID="myTextBo x"

'Make sure we add TB to server-side form
Page.FindContro l("Form1").Cont rols.Add(tb)

Dynamical controls need to be added to the Controls collection on every
request (when controls are declared statically in aspx, they are
automatically part of the Controls collection)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"sean" <se**********@s hopsmart.com.au > wrote in message
news:OK******** *****@tk2msftng p13.phx.gbl...
HI Teemu,

Thanks for your answer, it seems I am having a bit of troublemaking the
transition from asp to asp .net. Could you possibly help me out with a some
examples of two below? or give me a link to a website which illustrates the
examples that you have mentioned?

Sean

b) Create them dynamically in code and add to the Page's Controls
collection.
c) To create from markup at runtime, use Page.ParseContr ol(<control
declaration>) which returns a compiled control instance which you can place
to Page's Controls collection


"Teemu Keiski" <jo****@aspalli ance.com> wrote in message
news:OY******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

you can't write ASP.NET control declarations with Response.Write. Having
<asp:textBox> in page source is subject to compilation when the page is
first time requested. Response.Write writes the given string to the HTML
response, which is also generated/written by the compiled controls which
execute during Page's lifecycle. Using Response.Write does not cause
compilation to happen for controls(or this control on the Page). Compilation is crucial thing in page processing and you, in fact, can't avoid it to get things working.

You have three ways to declare controls:

a) Have them statically in aspx source
b) Create them dynamically in code and add to the Page's Controls
collection.
c) To create from markup at runtime, use Page.ParseContr ol(<control
declaration>) which returns a compiled control instance which you can place to Page's Controls collection

But you can't output control declarations using Response.Write and assume
that they get compiled as fully-working controls.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"sean" <se**********@s hopsmart.com.au > wrote in message
news:eL******** ******@tk2msftn gp13.phx.gbl...
Hi There,

I am trying to display some textboxes on my page, When I run the code the
textbox is written to the page (when I view source) but not to the screen.
Could someone tell me if I have the syntax correct?
Sean - thanks in advance for your answer

!-- code
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="Syst em.Data" %>
<% @Import Namespace="Syst em.Data.SqlClie nt" %>
<script language="vb" runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
If Not Page.IsPostBack then
BindData()
End If
End Sub
Sub BindData()
Dim dbRead As SqlDataReader
Dim strMFormControl as string
Dim strMFormValue as string
Dim strMDFormContro l as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(C onfigurationSet tings.AppSettin gs("connectionS tring"))

try
myConnection.Op en()
Dim myCommand As New SqlCommand("Get FormById", myConnection)
myCommand.Comma ndType = CommandType.Sto redProcedure

dbRead = myCommand.Execu teReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormContro l = dbRead(4)
response.write ("<form runat=server><t able border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMFormContro l,strMFormValue )
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem (strMDFormContr ol,strMDFormVal ue)

response.write ("</table></form>")

End While
dbRead.close

Catch oexpData As OleDb.OleDbExce ption
response.write ("an exception has occured,")
response.end
Finally
myConnection.cl ose
End Try

End Sub

!--- function here
Function DisplayFormItem (ByVal strMFormControl , ByRef strMFormValue)

Select Case Trim(strMFormCo ntrol)

Case "textbox"
response.write ("<asp:TextB ox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

Case "checkbox"

End Select

End Function

</script>



Nov 18 '05 #4

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

Similar topics

0
2883
by: Mark Johnson | last post by:
The last reply got sort of cutoff. So here again: So for anyone interested, here's the simple regexp patterns for the substitutions required. The textbox control is being 'zoomed' in a popup which uses a web browser control. As soon as any numeric entity gets put into the browser control, it's lost. It will display properly. But it can't be then read back out with document.body.innerHTML (or outerHTML). It's
2
8403
by: Hazzard | last post by:
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...
2
3921
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I did some work on was having the control implement the IValidator interface and basically recreating...
0
1239
by: Dot net work | last post by:
Hi, Make up a very simple project as follows: 1 aspx form 3 web user controls (referred to as A, B, and C) "A" web user control: Put 1 textbox and 1 button on this web user control. (You must do this exactly!)
7
2141
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
4
2706
by: Samy | last post by:
Hi There, I have a user control with a textbox and a button which when clicked opens a calendar control(calendar.aspx page). When I select a date from the calendar control, the date is supposed to be populated in the textbox. I use the user control on a index.aspx page. In order to achieve this I have a selected intexchange event on the calendar control. I pass the textbox id using the querystring when the button is clicked and then...
11
4580
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing opinion of how I want to handle the 'user experience' in the application I'm creating. While I know I could allow the user to enter in number and alpha text - in a text box - and then tell them when the execuate a command "This is not numeric data", I...
2
19875
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
6
8381
by: RP | last post by:
I want to clear all the Text Boxes on the Form. Is there any short method to avoid clearing them one by one.
8
36902
by: Marco Pais | last post by:
Hi there. How can I change the background color of a textbox when it gets the focus? I can handle the "Enter" event and do this private void txtDummie_Enter(object sender, EventArgs e) { txtDummie.BackColor=Color.Red; }
0
9621
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
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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
10039
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,...
1
7461
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
6716
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.