Programmatic equivalent of <form runat="server"> </from>

When designing an ASPX page, WebControls must be contained into a tag <form runat="server"></form>.

I am trying to achieve the same effect but in a programmatic manner within a .Net library (using HttpHandlers).


Does anyone has an idea how to do that?

Thanks in advance,
Joannès
Lokad.com, time-series forecasting
 

0
Joannes
1/15/2007 9:37:49 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
838 Views

Similar Articles

[PageSpeed] 29
Get it on Google Play
Get it on Apple App Store

Actually, I might have succeeded to solve this issue, but I am not too sure if it's the "right" way to do it.

public class MyPage : Page
{
    protected override void CreateChildControls()
    {
        HtmlForm htmlForm = new HtmlForm();
        Controls.Add(htmlForm);

        // snipped - add controls directly to 'htmlForm'
    }
}

 Does anyone could confirm (or not) if it is supposed to be done that way.

 
Thanks in advance,
Joannès
 

0
Joannes
1/15/2007 9:52:30 AM

Yes,

You can do it like this.

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
         
    ' Create a new HtmlForm control.
    Dim form As HtmlForm = New HtmlForm()
    form.ID = "ButtonForm"

    ' Create an HtmlButton control.
    Dim button As HtmlButton = New HtmlButton()
    button.InnerHtml = "Click Me"

    ' Register the event-handling method for the ServerClick event of the 
    ' HtmlButton control.
    AddHandler button.ServerClick, AddressOf Button_Click

    ' Add the HtmlButton control to the HtmlForm control.
    form.Controls.Add(button)

    ' Add the HtmlForm to the control collection of the page.
    Page.Controls.Add(form)
            
  End Sub

Zhao Ji Ma
Sincerely,
Microsoft Online Community Support

“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
0
Zhao
1/16/2007 8:17:58 AM
Reply:

Similar Artilces:

What if I remove <form id="form1" runat="server"></form>
If I am creating an aspx page, which does not need to be a form, i.e. no input is taken from the user, do I need to encapsulate the whole page with in  <form1 runat="server">   What are the implications of removing the form? I realize there will be no viewstate, and again, I won't be able to accept user input, but will everything else work as expected? It seems to be so far, I've just not seen ANY examples where the form tag has been removed. Thanks, Darragh You need the server-side form tag if you are going to have server-side controls on the form.RyanRyan Olshan...

can I delete <form id="form1" runat="server"> and </form>
Hi: Our website is written by using simple html code, one of the page has some virtual shopping cart code with <form> ....</form>, (for example here: http://www.centercoin.com/coin_supplies/coin_collecting_starter_set.htm ), if I have 10 products, I will have 10 of <from> ...</form> in this page, that is ok. Now, I am trying to redesign the website using asp.net2.0, I notice all the asp page will automatically create a <form id="form1" runat="server"> ...</form>, such as: <html xmlns="http://www.w3.org/19...

"<table></table>" and "<frameset><frame></frame></frameset>" in perl/tk
Dear my friends... Anybody would be so kind telling me what is similar in perl/tk to arrange the location of a form written in perl/tk? I want a nice look for my perl/tk application. Somewhat like this below: 1. Name : <place to type-in> 2. Address : <place to type-in> 3. Telephone : <place to type-in> I have made the main menu of my application with "Menubutton". And I want if the user click on the menu that what the user see is only the aimed application displayed on the determined area (under the main menu) but the menu has no change in po...

Code Behind or "<script runat="server">...code...</script>"?
Hi, I've just started learning asp.net after a number of years with VB. A lot of the examples I've been researching have placed the VB code directly onto the .aspx web page with a "<script runat="server">...code...</script>" format rather than placing the code in a "code behind" .vb page. Is there any reason for this other than the fact that you can place all the relevant code onto one example? From a .Net Studio point of view, it's seems to be far easier to use Code Behind, as one can take advantage of the "Auto Complete" features th...

<ypbp:CategoryTree id="categoryTree" runat="server"></ypbp:CategoryTree>
Hi All, I hope you can help a very confused beginner. I am writing a site that has a navigation tree configured from a database. I wanted to create a reusable piece of code that "draws" the navigation tree based on a request parameter that indicates to the code how to draw the tree. For example, the first time the page loads it will draw all the top level menu items only, and when a user clicks on one of those options it would draw all the top items and also the children of the item just clicked on etc... I want this to be reusable because I am writing an admin backend to the website as we...

<form id="form" runat="server">
hey i have a very similar problem to this thread http://forums.asp.net/thread/1440587.aspx"Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with r...

Why does <form runat="server"> render <div> around viewstate hidden variable?
I can't figure out why asp.net thinks it needs to render a div around the viewstate hidden variable, or if there's any way to get it to stop doing it:<form name="aspnetForm" method="post" action="default.aspx" id="aspnetForm" class="mainform"><div><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkZA1/6gmEk+w4wUiViNwm8AqBxBo1" /></div> It screws up attempts to style pages in certain ways, and since there's no way to put an id or cl...

Why is "<MyControl ... />" different to "<MyControl ...> </MyControl>"
Hi I have made a CompositeControl and had it working fine. The sequence of events was: Page -> Page_Load(), MyControl -> CreateChildControls(). This was fine because I had to set a certain property in my control during page load before CreateChildControls was called. Anyway.... suddenly it all stopped working and it turned out that the sequence of events changed to MyControl -> CreateChildControls(), Page -> Page_Load(). This caused it to blow up because the property was not set. After a few hours of pulling my hair out and undoing all the recent changes I had made it turns out...

Error on <form enctype="multipart/form-data" runat="server">
Hi to all... i have this problem which occured when i was uploading a picture into the SQL 2000. i am using VB script and Microsoft Visual Studio 2005... the error on"<pages enableEventValidation="true"/>"... can anyone help me??  i am using a master template for my webpage... everything work jus fine before i insert this "<form enctype="multipart/form-data" runat="server">" at the top of the page after "<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server&...

r31680 -[S32/Temporal] Added to Date: "There are also C<week>, C<week-year>, C<week-number>, C<weekday-of-month>, and C<day-of-year> methods, which work just like their DateTime equivalents."
Author: Kodi Date: 2010-07-14 16:35:46 +0200 (Wed, 14 Jul 2010) New Revision: 31680 Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod Log: [S32/Temporal] Added to Date: "There are also C<week>, C<week-year>, C<week-number>, C<weekday-of-month>, and C<day-of-year> methods, which work just like their DateTime equivalents." Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod =================================================================== --- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2010-07-14 14:35:21 UTC (rev 316...

<p><%# Server.HtmlEncode(Eval("Caption").ToString()) %></p>
what does that line of code do???    learning.. : ) It retrieves the string represention of the Caption field from the databinding context (maybe data from a database or an xml file), and encodes it as HTML (replacing "&" with "&amp;" etc.)  -- "Mark As Answer" if my reply helped you -- Also, use Eval's built-in string format, rather than calling ToString...<%# Server.HtmlEncode(Eval("Caption","{0}")) %>Much nicer for dates...<%# Eval("MyDate").ToShortDateString() %>&l...

<%= %> in <input type=text runat="server">
I want the input box to be 'automatically' filled from a select statement.  So, I have the following code that generates the following error... how do I get around this? CODE:   <input type="text" id="txtLastname" value="<%=Request["lastname"]%>" size="40" runat="server" /> ERROR: Warning 1 Generation of designer file failed: Server tags cannot contain <% ... %> constructs. V:\JournalApplied\EditReviewer.aspx 32 0 JournalApplied   Try after replacing ...

superreview requested: [Bug 226958] Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> : [Attachment 137491] (Cv2) <Wallet*.*> (+ <*pref*>)
Serge GAUTHERIE <gautheri@noos.fr> has asked Ben Goodger (I don't read bugmail) <bugs@bengoodger.com> for superreview: Bug 226958: Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> http://bugzilla.mozilla.org/show_bug.cgi?id=226958 Attachment 137491: (Cv2) <Wallet*.*> (+ <*pref*>) http://bugzilla.mozilla.org/attachment.cgi?id=137491&action=edit ...

superreview cancelled: [Bug 226958] Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> : [Attachment 137491] (Cv2) <Wallet*.*> (+ <*pref*>)
Serge GAUTHERIE <gautheri@noos.fr> has cancelled Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 226958: Bug 197315, "other" files: Convert <window class="dialog"> to <dialog> http://bugzilla.mozilla.org/show_bug.cgi?id=226958 Attachment 137491: (Cv2) <Wallet*.*> (+ <*pref*>) http://bugzilla.mozilla.org/attachment.cgi?id=137491&action=edit ...

Web resources about - Programmatic equivalent of <form runat="server"> </from> - asp.net.getting-started

Resources last updated: 12/2/2015 5:59:10 PM