conceptual problem

L

Lloyd Dupont

I'm trying to play with ASP.NET and I have some problem understanding how to
solve some problem, I wonder if I get it all wrong...

As an exercise for my firsts ASP.NET work I decided to write a Blog control
(in a WebControl library/DLL) and a website displaying it.
my page is like that (pseudo code)
=== default.aspx ===
<c#>
BlogEntry blog;
void PageLoad()
{
blog = BlogEngine.GetBlog(1);
blogControl.Blog = blog;
}
</c#>
<blog:BlogView runat=server ID=blogControl />
===============
the blog control is like that (pseudo code)
==== BlogView.cs ====
class BlogView : WebControl
{
BlogEdit blogEdit;
BlogDisplay blogView;

public BlogEntry Blog
{
set
{
EnsureChildControls();
blogEdit.Blog = value;
blogView.Blog = value;
}
}
}
==== BlogEdit.cs ======
class BlogEdit: WebControl
{
TextBox title;
FreeTextBox mainText;
LinkButton submit, cancel;

BlogEntry blog;
public BlogEntry Blog
{
set
{
EnsureChildControls();
mainText.Text = value.Text;
title.Text = value.Title;
}
}
void OnSubmit(EventArgs e)
{
blog.Text = mainText.Text;
blog.Title = title.Text;
}
}
================

Now my problem is:
when a blog has been edited and the user click on the submit button and the
OnSubmit() method is called the mainText & title.Text controls have the
original blog value set in and not the value entered by the user.

I guess it has to do with PageLoad() being called after the control have
been created.
But Iam at loss as how to solve that.
Maybe I'm calling the right method or something...

I hope I was clear enough I found my text confusing :S
If anybody could shed some light on good practice?

If possible without databing, I ... don't get them either... :S
 
L

Lloyd Dupont

I decided to put the code I have in Page_Load
{
blog = BlogEngine.GetBlog(1);
blogControl.Blog = blog;
}
In OnInit() instead and it worked well.

However it looks to me as being as a fragile behavior.
Because if, say in 1 year, I want to reuse this control in an other website,
I might use Page_Load again and it won't work.

So I wonder:
- is it bad programing to use Page_Load instead of OnInit() ?
- is there an obvious misconception in my code?
- any other idea?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top