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

replicate standard html form post functionality

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
(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

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

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.