1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

seeking clarification on how .NET defaults form attributes

Discussion in 'C#' started by chorizo, Aug 29, 2007.

  1. #1
    I've been reading up on the technology behind some of the pages I'm testing.

    Hoping I can provide enough detail so you can help clarify a comment in this article:

    If you select view source in an .aspx page containing a form with no name, method, action, or id attribute specified, you will see that ASP.NET has added these attributes to the form. It looks something like this:

    <form name="_ctl0" method="post" action="page.aspx" id="_ctl0">

    ...some code


    Am I right to assume that "page.aspx" represents the actual, physical location of the page on the server, regardless of the URL displayed by the browser?

    Here's why: I'm trying to figure out if there is some funky URL rewriting going on that my devs aren't disclosing. So, for example, I'm looking at a page that a browser displays at

    I know it is an ASP.NET page running server-side controls. When I view source, I see the entire page wrapped in:
    <form name="frmMain" method="post" action="../differentname.aspx?Filename=pagename" id="frmMain">.

    So, if I read the above commentary about runat="server" correctly:
    1. the attributes of <form runat="server"> have probably been filled in automatically
    2. the true location of the page is mysite.com/differentname.aspx, and
    3. content is being dynamically loaded - and the URL is rewriting - based on the filename parameter.

    From what I've provided, does it look like I am piecing this together properly?

    chorizo, Aug 29, 2007 IP
  2. garazy

    garazy Peon

    Likes Received:
    Best Answers:
    Trophy Points:
    Hi Chorizo,

    You are wrong in the page.aspx assumption. The location of action is where the form will be posted to by the browser, this is not necessarily the physical location of the file on the server, this is because the form tag is client side (on your browser). When you push submit it posts the information (method=post) with the data in the form to the URL in the action attribute.

    runat="server" is generic for all HTML tags in ASP.NET that when processed by ASP.NET will remove it and add other tags to the form.

    Confusingly if you try to add addition attributes to the form tag in the aspx page they will be removed when sent to the browser by ASP.NET, you have to use something like -

    myForm.Attributes.Add ( "myattribute" ,"myvalue" );

    In the page. A bit more detail than needed hope that helps.
    garazy, Aug 31, 2007 IP