Why does VS.NET use codebehind?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Why does VS.NET use codebehind?

    I'm reading the Essential ASP.NET book by Fritz onion and he says that when
    VS.NET creates a new .aspx page for you is uses the codebehind attribute on
    the Page directive rather than the src attribute. From what I understand the
    src attrib is standard ASP.NET but the codebehind attribute is only
    understood by VS.NET. Doesn't this make the pages (source code) less
    portable? Is there any reason for this?


    Hope someone can help.

    Graham


    Graham Allwood Guest

  2. Similar Questions and Discussions

    1. Data set in Codebehind
      When using dreamweaver for asp.net and VB can anyone tell me how to access the dataset (that DW created MM:Dataset ) in the code behind. All...
    2. Refreshing Page through CodeBehind --- Is it possible?
      Temp wrote: I presume that you mean some app running on the server? There isn't a way to do this server side once the page has been dispatched...
    3. Codebehind problem
      I have created a user control that gets loaded by a page. The user control has a codebehind, but when I change the code on the codebehind, it never...
    4. Popup in codebehind
      Hi. Is it possible to create a popup window (or something similar) from codebehind? Like after pressing a button and if som conditions is...
    5. src Versus codebehind
      hello friend, while developing an application, i encountered a subtle point. for a aspx page, what is the difference between src property and...
  3. #2

    Default Re: Why does VS.NET use codebehind?

    In Web Forms that use code-behind files, the @ Page directive (or @ Control
    in user control files) contains attributes that specify the relationship of
    the .aspx file and its code-behind file. These attribute are:

    a.. Codebehind In Visual Studio, this attribute references the name of a
    file that contains the class for the page. For example, if you create a Web
    Forms page in Visual Studio called WebForm1, the Codebehind attribute will
    point to WebForm1.aspx.vb or WebForm1.aspx.cs. This attribute is used only
    by the Visual Studio Web Forms Designer. It tells the designer where to find
    the page class so that the designer can create an instance of it for you to
    work with. The attribute is not used at run time.
    b.. Inherits Identifies the class from which the page derives. In Visual
    Studio, this points to a class in the project assembly (.dll), as shown in
    the diagram above.
    The code-behind model illustrated above is the model used by Visual Studio.
    The ASP.NET Framework supports a slightly different code-behind model for
    Web Forms pages. In the ASP.NET code-behind model, the visual elements are
    in an .aspx file and the code is in a separate code-only file, as in Visual
    Studio. However, there is no project, and the code is not pre-compiled.
    Instead, the code in the .vb or .cs file is compiled at run time, when the
    page is first requested by a user.

    The inheritance model works as illustrated above, with the difference that
    the Web Forms class (WebForm1 class in the diagram) is not part of a project
    assembly. Instead, each page is a separate assembly. There is no difference
    in how your code runs in the two models.

    In the ASP.NET code-behind model, there is no Codebehind page attribute,
    since that attribute is unique to Visual Studio. To tie the .aspx file to
    its corresponding code, the page directive contains a Src attribute, which
    references the file containing the source code for the file.

    The Src attribute is not supported in Visual Studio. If you import a Web
    Forms page into Visual Studio that contains the Src attribute, the designer
    will raise an error.



    For more details refer this link

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/[/url]
    vbconWebFormsCodeModel.asp


    --
    Saravana
    Microsoft India Community Star,
    MCAD,SE,SD,DBA.


    "Graham Allwood" <graham.allwood@eborsolutions.com> wrote in message
    news:#Hf6lYQTDHA.2152@TK2MSFTNGP12.phx.gbl...
    > I'm reading the Essential ASP.NET book by Fritz onion and he says that
    when
    > VS.NET creates a new .aspx page for you is uses the codebehind attribute
    on
    > the Page directive rather than the src attribute. From what I understand
    the
    > src attrib is standard ASP.NET but the codebehind attribute is only
    > understood by VS.NET. Doesn't this make the pages (source code) less
    > portable? Is there any reason for this?
    >
    >
    > Hope someone can help.
    >
    > Graham
    >
    >

    Saravana Guest

  4. #3

    Default Re: Why does VS.NET use codebehind?

    Your understanding is not entirely correct. The "Src" attribute is only used
    when the CodeBehind page is NOT compiled, and the CodeBehind code is in a
    separate file than the Page Template. It can't be used when the CodeBehind
    page is compiled into a DLL, or the source code is in the same file as the
    Page Template. It is similar in this respect to the "src" attribute of a
    JavaScript which uses an external .js file. The "CodeBehind" attribute is
    used by Visual Studio to identify the file being used during development, as
    there may not BE a "Src" attribute (because the codebehind is compiled, or
    because the CodeBehind may be in the same file as the Page Template). As for
    making the source code "less portable," what is that supposed to mean?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of little things.

    "Graham Allwood" <graham.allwood@eborsolutions.com> wrote in message
    news:%23Hf6lYQTDHA.2152@TK2MSFTNGP12.phx.gbl...
    > I'm reading the Essential ASP.NET book by Fritz onion and he says that
    when
    > VS.NET creates a new .aspx page for you is uses the codebehind attribute
    on
    > the Page directive rather than the src attribute. From what I understand
    the
    > src attrib is standard ASP.NET but the codebehind attribute is only
    > understood by VS.NET. Doesn't this make the pages (source code) less
    > portable? Is there any reason for this?
    >
    >
    > Hope someone can help.
    >
    > Graham
    >
    >

    Kevin Spencer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139