Showing posts with label code-behind. Show all posts
Showing posts with label code-behind. Show all posts

Saturday, March 31, 2012

Server side code in-side aspx

I usually use code-behind pages in ASP.Net, but occasionally I have to put my
server code inside an aspx file.
I have a problem finding the correct signature for a button click event.
Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles loginbtn.Click
compiles in in code behind, but it doesn't compile inside an aspx file.

How can I write a server event handler and put the code inside an asp file?That is the correct signature. What's the error you get?

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I usually use code-behind pages in ASP.Net, but occasionally I have to
> put my
> server code inside an aspx file.
> I have a problem finding the correct signature for a button click
> event.
> Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles loginbtn.Click
> compiles in in code behind, but it doesn't compile inside an aspx
> file.
> How can I write a server event handler and put the code inside an asp
> file?

Server side code in-side aspx

I usually use code-behind pages in ASP.Net, but occasionally I have to put m
y
server code inside an aspx file.
I have a problem finding the correct signature for a button click event.
Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles loginbtn.Click
compiles in in code behind, but it doesn't compile inside an aspx file.
How can I write a server event handler and put the code inside an asp file?That is the correct signature. What's the error you get?
-Brock
DevelopMentor
http://staff.develop.com/ballen

> I usually use code-behind pages in ASP.Net, but occasionally I have to
> put my
> server code inside an aspx file.
> I have a problem finding the correct signature for a button click
> event.
> Private Sub loginbtn_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles loginbtn.Click
> compiles in in code behind, but it doesn't compile inside an aspx
> file.
> How can I write a server event handler and put the code inside an asp
> file?
>

Tuesday, March 13, 2012

Server.MapPath Failing When Moved to Class Module

In a VB/ASP.NET project, the following lines work as advertised when placed
in a code-behind file (whatever.aspx.vb) - meaning that I get the full
physical path to MyDatabase.MDB in the variable PathToMDB. However, when the
same two lines are moved to a separate class file (whatever.vb), the project
fails to build - with the message "Name 'Server' is not declared."

Dim PathToMDB As String
PathToMDB = Server.MapPath("/MySite/db/") + "MyDatabase.mdb"

Why is this? What can I do about it? I need to obtain the physical path to
the MDB file from within the class file.

Thanks in advance."Jeff S" <JeffS@.asdf.net> wrote in message
news:uloQjlvoDHA.1928@.TK2MSFTNGP12.phx.gbl...
> In a VB/ASP.NET project, the following lines work as advertised when
placed
> in a code-behind file (whatever.aspx.vb) - meaning that I get the full
> physical path to MyDatabase.MDB in the variable PathToMDB. However, when
the
> same two lines are moved to a separate class file (whatever.vb), the
project
> fails to build - with the message "Name 'Server' is not declared."
> Dim PathToMDB As String
> PathToMDB = Server.MapPath("/MySite/db/") + "MyDatabase.mdb"
>
> Why is this? What can I do about it? I need to obtain the physical path to
> the MDB file from within the class file.
> Thanks in advance.

Try
HttpContext.Current.Server.MapPath("/MySite/db/") + "MyDatabase.mdb"

--
[[((hillarie))]]

To reply by email, remove ".SPAMBLOCK" from email address
Try it in this format:
MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("/") & "../data/myDB.mdb;"

David Wier
MCP, MVP ASP.NET, ASPInsider
http://aspnet101.com
http://aspexpress.com

"Jeff S" <JeffS@.asdf.net> wrote in message
news:uloQjlvoDHA.1928@.TK2MSFTNGP12.phx.gbl...
> In a VB/ASP.NET project, the following lines work as advertised when
placed
> in a code-behind file (whatever.aspx.vb) - meaning that I get the full
> physical path to MyDatabase.MDB in the variable PathToMDB. However, when
the
> same two lines are moved to a separate class file (whatever.vb), the
project
> fails to build - with the message "Name 'Server' is not declared."
> Dim PathToMDB As String
> PathToMDB = Server.MapPath("/MySite/db/") + "MyDatabase.mdb"
>
> Why is this? What can I do about it? I need to obtain the physical path to
> the MDB file from within the class file.
> Thanks in advance.