replicate standard html form post functionality

N

Not Me

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
 
K

Karl Seguin [MVP]

(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
 
N

Not Me

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
 
K

Karl Seguin [MVP]

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
 
N

Not Me

Karl said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top