473,503 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replicate standard html form post functionality

Hi,

I'm trying to translate a page into asp.net 2.0..

The options I need are e.g. action='some webpage', method=post,
enctype='enctype' etc... the file is supplied by a standard file input
dialog.

How can I post a file using asp.net? the form allows for some of the
above options, but as I'm using master pages I don't want this change to
affect other pages..(as the one form is used for all pages in the app)

cheers for your help,
Chris

Apr 25 '06 #1
4 1366
(1) Expose the form as a property of your master page:

<script runat="server">
Friend ReadOnly Property Form() As HtmlForm
Get
Return form1
End Get
End Property
</script>
(2)
Sepcify the type of your master page in your page:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
(3)
Access the form in your page

Master.Form.Attributes.Add("action", "whatever.html")
....
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Not Me" <no****@zxy.blah.org> wrote in message
news:e2**********@ucsnew1.ncl.ac.uk...
Hi,

I'm trying to translate a page into asp.net 2.0..

The options I need are e.g. action='some webpage', method=post,
enctype='enctype' etc... the file is supplied by a standard file input
dialog.

How can I post a file using asp.net? the form allows for some of the above
options, but as I'm using master pages I don't want this change to affect
other pages..(as the one form is used for all pages in the app)

cheers for your help,
Chris

Apr 25 '06 #2
Hi Karl,

That looks great.. and definitely points me in the right direction..
unfortunately I am stuck :)

I get errors telling me the form() property is private, even though it's
set as friend. the only way to circumvent this is to make it public.

Once I've done the above, not a lot seems to be happening. specifically
the 'action' of the form isn't being triggered and I'm not being sent
elsewhere. Do I need to set the redirect programmatically? It would
seem that would negate the need for an action attribute anyway...

cheers for your input
Chris

Karl Seguin [MVP] wrote:
(1) Expose the form as a property of your master page:

<script runat="server">
Friend ReadOnly Property Form() As HtmlForm
Get
Return form1
End Get
End Property
</script>
(2)
Sepcify the type of your master page in your page:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
(3)
Access the form in your page

Master.Form.Attributes.Add("action", "whatever.html")
...
Karl

Apr 26 '06 #3
Yes, public makes more sense since each file is put into it's own assembly.

This is a little test I did:

<%@ Master Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Public ReadOnly Property Form() As HtmlForm
Get
Return form1
End Get
End Property
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled
Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>
<script runat="server">
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Master.Form.Attributes.Add("action", "test.html")
MyBase.OnLoad(e)
End Sub
</script>

and it worked great...
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Not Me" <no****@zxy.blah.org> wrote in message
news:e2**********@ucsnew1.ncl.ac.uk...
Hi Karl,

That looks great.. and definitely points me in the right direction..
unfortunately I am stuck :)

I get errors telling me the form() property is private, even though it's
set as friend. the only way to circumvent this is to make it public.

Once I've done the above, not a lot seems to be happening. specifically
the 'action' of the form isn't being triggered and I'm not being sent
elsewhere. Do I need to set the redirect programmatically? It would seem
that would negate the need for an action attribute anyway...

cheers for your input
Chris

Karl Seguin [MVP] wrote:
(1) Expose the form as a property of your master page:

<script runat="server">
Friend ReadOnly Property Form() As HtmlForm
Get
Return form1
End Get
End Property
</script>
(2)
Sepcify the type of your master page in your page:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
(3)
Access the form in your page

Master.Form.Attributes.Add("action", "whatever.html")
...
Karl

Apr 26 '06 #4
Karl Seguin [MVP] wrote:
This is a little test I did:

<%@ Master Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Public ReadOnly Property Form() As HtmlForm
Get
Return form1
End Get
End Property
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled
Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>
<script runat="server">
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Master.Form.Attributes.Add("action", "test.html")
MyBase.OnLoad(e)
End Sub
</script>


Thank you for that, I can run your example fine, it's just when I try
and make it into code-behind that I get the errors.. so I'll leave that
project for another time ;)

For now though, even without errors, how do I get the action to
'action'? You didn't put any controls into your form that would allow
that.. if I put an input button, or an asp button - once clicked I just
get a standard refresh.

Cheers,
Chris
Apr 28 '06 #5

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

Similar topics

0
1159
by: Paul Hobbs | last post by:
Hi All, I am trying to replicate the functionality of the HTML FileField control. I can use it just fine to prompt a user to browse to a file, and it retrieves the full path just fine. I can...
0
2388
by: Paul Hobbs | last post by:
Hi All, I am trying to replicate the functionality of the HTML FileField control. I can use it just fine to prompt a user to browse to a file, and it retrieves the full path just fine. I can...
0
1591
by: bp_jobemail | last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes into a precompiled C cgi script. Essentially, the company that I work for uses a purchased precompiled c program for their...
4
1650
by: dustin | last post by:
I've been hacking away on this PEP for a while, and there has been some related discussion on python-dev that went into the PEP: ...
0
7205
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,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
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,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
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...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
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...

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.