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
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