views:

39

answers:

2

Hello All,

I have the following HTML content. When i click the button, the page doesn't post to URL provided in action tag. The corresponding application is running, but still the page load of the CrossPage.aspx was not invoked. What could be the problem?

<body>
<form id="UploadForm" method="post"  enctype="multipart/form-data" action="http://localhost:2518/Web/CrossPage.aspx"&gt;
<div>
<input type="file" id="BtnUpload" />
<input type="button" id="BtnSubmit"  value="Submit" />
</div>
</form>
</body>
+1  A: 

Change "button" to "submit"

<body>
  <form id="UploadForm" method="post"  enctype="multipart/form-data" action="http://localhost:2518/Web/CrossPage.aspx"&gt;
    <div>
      <input type="file" id="BtnUpload" />
      <input type="submit" id="BtnSubmit"  value="Submit" />
    </div>
  </form>
</body>

To your <asp:button>you have not just the Text but also the runat attribute right?

These w3schools pages may help you

Dan McGrath
Thanks Dan. When i try to use <asp:Button> the page doesn't post so what could be the reason for that too
Sri Kumar
Added a new bit about the asp:button control and another link for you.
Dan McGrath
No, the asp:button doesn't post the page to given URL.
Sri Kumar
Can you post your actual asp.net code then?
Dan McGrath
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" w3.org/TR/xhtml1/DTD/…; <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Untitled Page</title></head><body><form id="UploadForm" method="post" enctype="multipart/form-data" action="http://localhost:2518/Web/CrossPage.aspx" runat="server"> <div><input type="file" id="BtnUpload" /><asp:Button ID="Button1" Text="Submit" runat="server" onclientclick="Submit"/></div></form></body></html>
Sri Kumar
+1  A: 

If you are using the asp:button control in ASP.NET you might want to add the runat="server" to your "form".

<form runat="server" id="UploadForm" method="post"  enctype="multipart/form-data" action="http://localhost:2518/Web/CrossPage.aspx"&gt;

Also if you do not want to implement the server side event handler for submit, you can use the onclientclick="submit".

<body>
<form id="UploadForm" method="post"  enctype="multipart/form-data" action="http://localhost:2518/Web/CrossPage.aspx" runat="server">
<div>
<input type="file" id="BtnUpload" />
<asp:Button Text="Submit" runat="server" onclientclick="Submit" />
</div>
</form>
</body>

This works for me.

Preets
I copied the code and pasted it. But it doesn't work for me :(
Sri Kumar
OK, What is the error you receive? Also, what version of ASP.NET are you using?
Preets
I don't receive any error. 3.5 is my version
Sri Kumar
Could you please you post the aspx and aspx.cs code for your form?
Preets
Did you create the forms from scratch, or did VS create the forms for you? I can suggest adding a new web form and then pasting this code in the <body> section of the aspx.
Preets
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Untitled Page</title></head><body><form id="UploadForm" method="post" enctype="multipart/form-data" action="http://localhost:2518/Web/CrossPage.aspx" runat="server"><div><input type="file" id="BtnUpload" /><asp:Button ID="Button1" Text="Submit" runat="server" onclientclick="Submit"/></div></form></body></html>
Sri Kumar
i don't have c# coding.
Sri Kumar
Sri Kumar, I tested the code you have pasted and it worked for me. That is, when I clicked the Submit button it redirected me to http://localhost:2518/Web/CrossPage.aspx (Obviously, since the file CrossPage.aspx does not exist on my machine, I get an error, but the redirection works fine)
Preets
Thanks :) I changed the whole logic to post the file. Now I am using HttpWebRequest
Sri Kumar
Sri Kumar, good to know you got it working :)
Preets