Showing posts with label webpage. Show all posts
Showing posts with label webpage. Show all posts

Saturday, March 31, 2012

server side control not visible in webpage

Hey there-
I have a newbie question regarding code behind:
Using inline code, I can run a simple page that binds data to a
datagrid. Now, I try to take the same code and use code behind, and
the page compiles fine, but no HTML is rendered to the page.
Here is the code from "WebForm1.aspx"
<%@dotnet.itags.org. Page Language="vb" Inherits="WebForm1" src="http://pics.10026.com/?src=WebForm1.aspx.vb" %>
<html>
<head>
<title>WebForm1</title>
</head>
<body>
<asp:datagrid id="datGrid" runat="server"/>
</body>
</html>
--
And here is the code for "WebForm1.aspx.vb"
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
BindData()
End Sub
Sub BindData()
'1. Create a connection
Dim AccessConn As System.Data.OleDb.OleDbConnection
Dim AccessCommand As System.Data.OleDb.OleDbCommand
Dim AccessReader As System.Data.OleDb.OleDbDataReader
Dim strConn As String
Dim datGrid As New DataGrid
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\inetpub\wwwroot\AddressBook\da
tabase\Address.mdb;"
AccessConn = New System.Data.OleDb.OleDbConnection(strConn)
'2. Create the command object, passing in the SQL string
Const strSQL As String = "SELECT ID, LastName, FirstName FROM
tblAddress ORDER BY LastName"
Dim myCommand As New System.Data.OleDb.OleDbCommand(strSQL,
AccessConn)
'Set the datagrid's datasource to the datareader and databind
AccessConn.Open()
datGrid.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
datGrid.DataBind()
End Sub
End Class
--
A couple of notes:
1) I removed the "Web Form Designer Generated Code" for simplicity
2) Why do I need to declare datGrid? None of the examples I have seen
don't declare the server controls.
Regards,
ChristianChristian,

> 1) I removed the "Web Form Designer Generated Code" for simplicity
Don't do that! JK! I would suggest trying your example with the web form des
igner code cause your datagrid object is initialized in there. Also make sur
e your query is returning rows.
-Calvin Luttrell
ProjectThunder.com
Calvin-
I didn't remove the code from the actual aspx file, just in the
example here. My query is returning rows. Like I mentioned in the
previous post, everything works great if I use inline code, it's when
I modify it to code behind that the control doesn't render.
Christian
"Calvin Luttrell/ProjectThunder.com" <calvinl@.projectthunder.com> wrote in message news:<Ov
6WqlUQEHA.2520@.TK2MSFTNGP11.phx.gbl>...
> Christian,
>
> Don't do that! JK! I would suggest trying your example with the web form
> designer code cause your datagrid object is initialized in there. Also
> make sure your query is returning rows.
>
> -Calvin Luttrell
> ProjectThunder.com
>
>
>
>
> --

server side control not visible in webpage

Hey there-

I have a newbie question regarding code behind:

Using inline code, I can run a simple page that binds data to a
datagrid. Now, I try to take the same code and use code behind, and
the page compiles fine, but no HTML is rendered to the page.

Here is the code from "WebForm1.aspx"

------
<%@dotnet.itags.org. Page Language="vb" Inherits="WebForm1" src="http://pics.10026.com/?src=WebForm1.aspx.vb" %>
<html>
<head>
<title>WebForm1</title>
</head>
<body
<asp:datagrid id="datGrid" runat="server"/
</body>
</html>
-------

And here is the code for "WebForm1.aspx.vb"

-------
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data

Public Class WebForm1
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
BindData()
End Sub

Sub BindData()

'1. Create a connection
Dim AccessConn As System.Data.OleDb.OleDbConnection
Dim AccessCommand As System.Data.OleDb.OleDbCommand
Dim AccessReader As System.Data.OleDb.OleDbDataReader
Dim strConn As String
Dim datGrid As New DataGrid

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\inetpub\wwwroot\AddressBook\database\Add ress.mdb;"
AccessConn = New System.Data.OleDb.OleDbConnection(strConn)

'2. Create the command object, passing in the SQL string
Const strSQL As String = "SELECT ID, LastName, FirstName FROM
tblAddress ORDER BY LastName"
Dim myCommand As New System.Data.OleDb.OleDbCommand(strSQL,
AccessConn)

'Set the datagrid's datasource to the datareader and databind
AccessConn.Open()
datGrid.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
datGrid.DataBind()
End Sub

End Class
-------

A couple of notes:

1) I removed the "Web Form Designer Generated Code" for simplicity
2) Why do I need to declare datGrid? None of the examples I have seen
don't declare the server controls.

Regards,

ChristianChristian,

> 1) I removed the "Web Form Designer Generated Code" for simplicity

Don't do that! JK! I would suggest trying your example with the web form designer code cause your datagrid object is initialized in there. Also make sure your query is returning rows.

-Calvin Luttrell
ProjectThunder.com


Calvin-

I didn't remove the code from the actual aspx file, just in the
example here. My query is returning rows. Like I mentioned in the
previous post, everything works great if I use inline code, it's when
I modify it to code behind that the control doesn't render.

Christian

"Calvin Luttrell/ProjectThunder.com" <calvinl@.projectthunder.com> wrote in message news:<Ov6WqlUQEHA.2520@.TK2MSFTNGP11.phx.gbl>...
> Christian,
> > 1) I removed the "Web Form Designer Generated Code" for simplicity
> Don't do that! JK! I would suggest trying your example with the web form
> designer code cause your datagrid object is initialized in there. Also
> make sure your query is returning rows.
>
> -Calvin Luttrell
> ProjectThunder.com
>
>
>
>
> --

Server side HTML printing

Hi,
I am using a rich text editor (FCKEdit) on a webpage in which user can
enter formatted text.
The output of this control is HTML. Now on the code behind side, I need
to change some of this HTML and then print the HTML (the pretty
document - not the code) on the server printer.
Any ideas'
Thanks in advance<sprash25@.gmail.com> wrote in message
news:1149837637.843058.67720@.i39g2000cwa.googlegroups.com...
> Hi,
> I am using a rich text editor (FCKEdit) on a webpage in which user can
> enter formatted text.
> The output of this control is HTML. Now on the code behind side, I need
> to change some of this HTML and then print the HTML (the pretty
> document - not the code) on the server printer.
> Any ideas'
> Thanks in advance
>
Well, I can help you with the capture of the html side. The printing is
another matter. This code will capture the html just before it get sent to
the client. You also google for 'asp.net output html save'
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)
Dim html As String = _stringBuilder.ToString()
'here is where you can manipulate or save to file or database or maybe print
the html output string
writer.Write(html) 'this writes the page back out
End Sub
Mike

Server side HTML printing

Hi,

I am using a rich text editor (FCKEdit) on a webpage in which user can
enter formatted text.
The output of this control is HTML. Now on the code behind side, I need
to change some of this HTML and then print the HTML (the pretty
document - not the code) on the server printer.

Any ideas??

Thanks in advance<sprash25@.gmail.com> wrote in message
news:1149837637.843058.67720@.i39g2000cwa.googlegro ups.com...
> Hi,
> I am using a rich text editor (FCKEdit) on a webpage in which user can
> enter formatted text.
> The output of this control is HTML. Now on the code behind side, I need
> to change some of this HTML and then print the HTML (the pretty
> document - not the code) on the server printer.
> Any ideas??
> Thanks in advance
Well, I can help you with the capture of the html side. The printing is
another matter. This code will capture the html just before it get sent to
the client. You also google for 'asp.net output html save'

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)

Dim html As String = _stringBuilder.ToString()

'here is where you can manipulate or save to file or database or maybe print
the html output string

writer.Write(html) 'this writes the page back out

End Sub

Mike