ASP.NET Web Page Code Model, hangisini seçmeli?

July 25, 2008 at 4:44 PMoozturk

ASP.NET için iki kod modeli var, bunlar:

- Single-File Page Model

- Code-Behind Page Model

Peki hangisini seçmeli?

Öncelikle belirtmek gerekiyorki microsoft'un açıklamasına göre (bir kaç kere test ettim, gerçekten öyle) herhangi bir performans farkı yok, tamamen şahsi seçime bağlı. Aslında şahsi seçimler de durumlara göre yapıldığına göre, durumuna göre değişir de diyebiliriz.

Mesela eğer kendimizi geliştirmek için bir örnek çalışıyorsak ya da az kodlu bir sayfa olacaksa, single-file page model daha uygun bir seçim olabilir. Sebep olarak da:

   - Markup (kullanıcı arayüzü) ve kodlar aynı sayfada olacağından ötürü daha okunaklı ve daha hakim olacağımız bir ortam oluşturur.

   - Bir başka şahısla paylaşacaksak sayfayı, göndermesi daha kolay olur (netice de bir tek dosyadan oluşuyor)

gibi bazı örnekler verilebilir. Bu tip bir çalışmaya aşağıda bir örnek vereyim.

<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click(Object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
}
</script>
<html>
<head>
  <title>Single-File Page Model</title>
</head>
<body>
  <form runat="server">
    <div>
       <asp:Label id="Label1"
         runat="server" Text="Label">
       </asp:Label>
       <br />
       <asp:Button id="Button1"
         runat="server"
         onclick="Button1_Click"
         Text="Button">
      </asp:Button>
    </div>
  </form>
</body>
</html>

Code-Behind page model'i ise ciddi çalışmalarımızda ve çok kodlu çalışmalarımızda kullanmamız daha mantıklı olacaktır. Yine birkaç sebep belirtmek gerekirse:

   - Markup ve kodlar ayrı sayfalarda olacağından ötürü kod yazarıyla tasarımcı aynı anda çalışabilir, bu da zamandan tasarruf sağlayıp verimliliği arttırır.

   - Kodu markup'dan ayıklamaya gerek kalmayacağı için rahatça başka sayfalarda da kullanılabilir.

   - Kodu tasarımcı görmeyeceği için, bir nevi güvenlik de sağlamış oluruz.

 Bu sebepler çoğaltılabilir. Bir de code-behind'a örnek kod vereyim.

SamplePage.aspx

 <%@ Page Language="C#" CodeFile="SamplePage.aspx.cs"
    Inherits="SamplePage" AutoEventWireup="true" %>
<html>
<head runat="server" >
   <title>Code-Behind Page Model</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
       <asp:Label id="Label1"
         runat="server" Text="Label" >
      </asp:Label>
      <br />
      <asp:Button id="Button1"
         runat="server"
         onclick="Button1_Click"
         Text="Button" >
       </asp:Button>
    </div>
  </form>
</body>
</html>

SamplePage.aspx.cs 

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SamplePage : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToString();
    }
}
 

Netice de tamamen alışkanlıklara ve tercihlere göre insandan insana değişir bu seçim.

Posted in: ASP.NET

Tags:

Comments (75) -

Certainly, the blogpost is actually the most desirable on this beneficial subject. I fit in with your findings and will desperately look forward to your  forthcoming updates. Saying thankx will never just be enough, for the helpful lucidity in your writing. I will immediately grab your feed to stay informed of any updates. Solid work and much success in your business endeavors! Thank you very much, ..

Reply

I would just say one thing to you and that is, “FANTASTIC”!! Keep it up and wish to get more details from your blog.

Reply

Its a pity you dont have a donate button, i would donate some =)

Reply

Hey check out my blog too. I hope i have some interesting stuff too

Reply

Its a pity you dont have a donate button, i would donate some =)

Reply

If i want to be more descriptive without doubt i may consider adding a few images. Surely I don't want to be rude about what you have blogged. Keep it going, but put a little more into it other time.

Reply

How did you make this blog site look this good!? Email me if you want and share your wisdom. I'd be appreciative!

Reply

This blog has got lots of very helpful information on it. Thanks for helping me!

Reply

I'm getting a javascript error, is anyone else?

Reply

How do you make this site look this sick!? Email me if you can and share your wisdom. I'd appreciate it!

Reply

This really answered my problem, thank you!

Reply

Please message me with any hints on how you made your website look like this , I'd appreciate it.

Reply

Please message me with a few pointers about how you made this site look this awesome , I would be appreciative.

Reply

Have you considered adding some differing opinions to the article? I think it will really enhance my understanding.

Reply

This website is extremely good. How was it made ?

Reply

How did you make this blog look this cool! Email me if you can and share your wisdom. I'd be appreciative!

Reply

An interesting blog post there mate ! Cheers for that !

Reply

This website is really good! How was it made !?

Reply

Dude! This blog site is amazing. How did you  make it look like this ?

Reply

This blog has a lot of really helpful info on it! Thanks for helping me.

Reply

This website is very good! How can I make one like this ?

Reply

This blog site has a lot of extremely useful information on it. Thank you for informing me!

Reply

I adore this website layout . How was it made? It is very nice.

Reply

I'm getting a javascript error, is anyone else?

Reply

This really solved my problem, thank you!

Reply

Great site design!!!! Whattemplate did you use?

Reply

Can you message me with any tips about how you made your blog site look like this, I would be thankful.

Reply

Have you thought about adding some relevant links to your article? I think it might enhance my understanding.

Reply

I'm getting a browser error, is anyone else?

Reply

A interesting post right there mate ! Cheers for it !

Reply

Brilliant, cheers, I will visit again now!

Reply

This blog is pretty cool. How was it made !?

Reply

Have you considered adding some videos to the article? I think it will really enhance everyone's understanding.

Reply

When are you going to post again? You really entertain  a lot of people!

Reply

This blog is very cool! How can I make one like this !

Reply

Amazing article, thank you, I will subscribe to you RSS later!

Reply

This really solved my problem, thank you!

Reply

Who needs newspapers when they have such a nice blog to read. I was really wondering on this subject so I went to Bing, typed my question and voila, here I landed. Such a pleasant surprise to get to your blog. Thank you for your time and for this wonderful post. Thank you smarte search engine for bringing me here.

Reply

Can you email me with a few pointers about how you made this blog site look this good , I'd be appreciative.

Reply

An cool post right there mate . Thanks for that !

Reply

Awesome post ! Cheers for, visiting my blog page mate. I will email you some time. I didn't realise that.

Reply

This website is very cool. How can I make one like this !

Reply

Mate! This website is amazing. How did you  make it look like this !?

Reply

Nice post . Thanks for, visiting my blog man! I'll email you again. I didn't realise that!

Reply

I adore the website layout ! How do you make it!? It is so nice!

Reply

Have you thought about adding some relevant links to your article? I think it will really enhance everyone's understanding.

Reply

Have you thought about adding some differing opinions to your article? I think it might enhance everyone's understanding.

Reply

Can you email me with a few hints on how you made this blog look this awesome , I'd appreciate it.

Reply

Cool post ! Thanks for, posting on this blog dude. I'll email you soon! I didn't realise that.

Reply

Please email me with any pointers on how you made your website look like this , I'd appreciate it.

Reply

I adore this blog site layout ! How did you make it? It's really sweet.

Reply

If you could message me with any hints about how you made your blog look like this , I would be appreciative.

Reply

A insightful blog post there mate . Thank you for posting .

Reply

This really solved my problem, thank you!

Reply

I adore this blog layout ! How did you make it!? It is so cool!

Reply

Brilliant, thank you, I will bookmark you later!

Reply

Cool post . Thank you for, writing on this blog page man. I'll message you again! I didn't know that!

Reply

Nice post . Cheers for, commenting on my blog mate. I shall email you again. I didn't realise that!

Reply

Could you email me with some tips on how you made your site look this awesome , I would be thankful.

Reply

Awesome post . Thanks for, posting on my blog mate. I shall message you soon. I did not know that!

Reply

If you could email me with a few tips on how you made your website look this cool, I'd appreciate it!

Reply

Have you thought about adding some videos to your article? I think it will really enhance my understanding.

Reply

This blog has got a lot of very useful information on it! Thank you for sharing it with me!

Reply

This website has got some extremely useful information on it. Thanks for helping me!

Reply

A insightful blog post there mate . Thanks for it .

Reply

Awesome post . Thanks for, commenting on this blog dude! I will email you again! I did not realise that.

Reply

I love that blog layout ! How was it made. It is so cool.

Reply

Brilliant, cheers, I will bookmark you later.

Reply

Awesome post ! Thanks for, writing on my blog page dude! I'll email you some time. I didn't know that!

Reply

How do you make this blog site look this sick. Email me if you can and share your wisdom. I'd be thankful!

Reply

A insightful post there mate ! Thank you for posting !

Reply

Awesome post ! Cheers for, writing on this blog man. I shall message you some time. I did not know that!

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading