6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » .NET General » How can I embed DotNet form in html?
       
Author Reply
shanthi pocha
posted 2 posts
since Oct 22, 2011 
from

How can I embed DotNet form in html?

  Posted on: 22 Oct 2011       
I have html,css,javascript files in a folder called "web html" and have a mail form in dotnet as "web application1" folder.
Now I need to embed dotnet mail form in html?
How can I embed? Please help..



Thanks in advance..
Hemant Kumar
posted  313 posts
since  Sep 14, 2009 
from  Hyderabad

 Re: How can I embed DotNet form in html?
  Posted on: 22 Oct 2011        0  

Let's say that you have an ASP.NET page that get's a content feed from your blog. In your feed there is an embedded HTML form that posts to another website. If you simply embed this form, the containing ASP.NET form will override the embedded ASP.NET form and it will just do a normal PostBack not post the embedded HTML form.

Here is a workaround that we've used. 


Close the ASP.NET form tag before your embedded content form begins, then create a dummy form tag after your embedded form is closed to clean up the ASP.NET inserted </form> tag. This allows your embedded form to work and prevents HTML validation errors.

A base asp.net form looks like this....

[Wire up and head stuff here...]
<body>
<form id="form1" runat="server">
  <div>
    Hello World!
  </div>
</form>
</body>
</html>


Let's say that instead of Hello World I have an asp literal that is populated with content from say a blog feed that contains a feedback form. (or I could have just pasted an HTML form from some other source). My code now looks like this...

<body>
<form id="form1" runat="server">
  <div>
    <asp:literal id="litBlogContent" runat="server" />
  </div>
</form>
</body>
</html>


The way to implement this solution is as follows.....

<body>
<form id="form1" runat="server">
  <div>
  </form> <!-- Close the ASP.NET "form1" -->
    <asp:literal id="litBlogContent" runat="server" />
  </div>
<!-- Remove the ASP.NET close form tag that .NET inserted at the bottom of the page. -->
<!-- </form> -->
</body>


If you have a standard WebForm this works fine. If however you are using Master Pages, and your embedded form is in a content page, then you don't have access to the close form tag, so the you need to create a "fake" form to close the </form> tag embedded in your HTML page.

<asp:Content ID="Content1" ContentPlaceHolderID="UpperBody" Runat="Server">
  </form> <!-- Close the ASP.NET close form tag that's embedded in the master page. -->
  <div>
    <asp:literal id="litBlogContent" runat="server" />
  </div>
  <form id="dummyForm"> <!-- put in a dummy form to deal with the </form> tag that's embedded at the end of the master page. -->
</asp:Content>


VisualStudio will give you a warning that there are missing open and close tags, you can just ignore these, what's important is that the rendered HTML when the form runs will validate.

If you have multiple forms on your page, you'll need to make sure that your ASP.NET form and input fields are BEFORE you insert the close form tag, and before your HTML form. Using this method, only one form will submit, the ASP.NET form or the HTML form.

UPDATE: I've been asked to show an embedded standard HTML form, so here is an example with just a simple HTML form.

Standard WebForm....

<body>
<form id="form1" runat="server">
  <div>
  </form> <!-- Close the ASP.NET "form1" -->
  <form id="standardHtmlForm" method="post"
      action="http://www.thirdPartySite.com/post.aspx">
    Field: <input id="txtInputField" type="text"></input>
    <input type="submit" value="Submit">
  </form>
  </div>
<!-- Remove the ASP.NET close form tag that .NET inserted at the bottom of the page. -->
<!-- </form> -->
</body>


Or with a master page.....

<asp:Content ID="Content1" ContentPlaceHolderID="UpperBody" Runat="Server">
  </form> <!-- Close the ASP.NET "form1" -->
  <form id="standardHtmlForm" method="post"
      action="http://www.thirdPartySite.com/post.aspx">
    Field: <input id="txtInputField" type="text"></input>
    <input type="submit" value="Submit">
  </form>
<form id="dummyForm"> <!-- put in a dummy form to deal with the </form> tag that's embedded at the end of the master page. -->
</asp:Content>

Check this link
http://stackoverflow.com/questions/588981/using-embedded-standard-html-forms-with-asp-net
Mark as "Accepted Answer" if it helps you .


       
Top Articles
View all »
Nevron Gauge for SharePoint
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved