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

textbox control

P: n/a
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:TextBox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load(sender 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 strMDFormControl as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))

try
myConnection.Open()
Dim myCommand As New SqlCommand("GetFormById", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

dbRead = myCommand.ExecuteReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormControl = dbRead(4)
response.write ("<form runat=server><table border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMFormControl,strMFormValue)
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMDFormControl,strMDFormValue)

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

End While
dbRead.close

Catch oexpData As OleDb.OleDbException
response.write ("an exception has occured,")
response.end
Finally
myConnection.close
End Try

End Sub

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

Select Case Trim(strMFormControl)

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

Case "checkbox"

End Select

End Function

</script>


Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.ParseControl(<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**********@shopsmart.com.au> wrote in message
news:eL**************@tk2msftngp13.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:TextBox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load(sender 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 strMDFormControl as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))

try
myConnection.Open()
Dim myCommand As New SqlCommand("GetFormById", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

dbRead = myCommand.ExecuteReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormControl = dbRead(4)
response.write ("<form runat=server><table border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMFormControl,strMFormValue)
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMDFormControl,strMDFormValue)

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

End While
dbRead.close

Catch oexpData As OleDb.OleDbException
response.write ("an exception has occured,")
response.end
Finally
myConnection.close
End Try

End Sub

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

Select Case Trim(strMFormControl)

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

Case "checkbox"

End Select

End Function

</script>

Nov 18 '05 #2

P: n/a
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.ParseControl(<control
declaration>) which returns a compiled control instance which you can place
to Page's Controls collection


"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:OY**************@TK2MSFTNGP12.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.ParseControl(<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**********@shopsmart.com.au> wrote in message
news:eL**************@tk2msftngp13.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:TextBox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load(sender 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 strMDFormControl as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))

try
myConnection.Open()
Dim myCommand As New SqlCommand("GetFormById", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

dbRead = myCommand.ExecuteReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormControl = dbRead(4)
response.write ("<form runat=server><table border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMFormControl,strMFormValue)
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMDFormControl,strMDFormValue)

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

End While
dbRead.close

Catch oexpData As OleDb.OleDbException
response.write ("an exception has occured,")
response.end
Finally
myConnection.close
End Try

End Sub

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

Select Case Trim(strMFormControl)

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

Case "checkbox"

End Select

End Function

</script>


Nov 18 '05 #3

P: n/a
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="myTextBox"

'Make sure we add TB to server-side form
Page.FindControl("Form1").Controls.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**********@shopsmart.com.au> wrote in message
news:OK*************@tk2msftngp13.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.ParseControl(<control
declaration>) which returns a compiled control instance which you can place
to Page's Controls collection


"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:OY**************@TK2MSFTNGP12.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.ParseControl(<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**********@shopsmart.com.au> wrote in message
news:eL**************@tk2msftngp13.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:TextBox runat=server id=" & strMFormValue &"
/></td></tr>" & Vbcrlf)

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
Sub Page_Load(sender 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 strMDFormControl as string
Dim strMDFormValue as string

Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))

try
myConnection.Open()
Dim myCommand As New SqlCommand("GetFormById", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

dbRead = myCommand.ExecuteReader()

While dbRead.Read ( )

strMFormValue = dbRead(1)
strMFormControl = dbRead(2)
strMDFormValue = dbRead(3)
strMDFormControl = dbRead(4)
response.write ("<form runat=server><table border=1 align=center>" &
Vbcrlf & _
"<tr><td colspan=2>" & dbRead(0) & "</td></tr>" & Vbcrlf & _
"<tr><td>" & strMFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMFormControl,strMFormValue)
response.write ("<tr><td>" & strMDFormValue & "</td><td>" & Vbcrlf)
DisplayFormItem(strMDFormControl,strMDFormValue)

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

End While
dbRead.close

Catch oexpData As OleDb.OleDbException
response.write ("an exception has occured,")
response.end
Finally
myConnection.close
End Try

End Sub

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

Select Case Trim(strMFormControl)

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

Case "checkbox"

End Select

End Function

</script>



Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.