473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

conceptual problem

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
Jan 4 '06 #1
2 1290
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?

"Lloyd Dupont" <net.galador@ld> wrote in message
news:uc**************@TK2MSFTNGP14.phx.gbl... 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

Jan 4 '06 #2
Youpiiyoup!!
Solved it with the following IF statment:
public BlogEntry Blog
{
set
{
EnsureChildControls(); if(!Page.IsPostback)
{ mainText.Text = value.Text;
title.Text = value.Title; } }
}

"Lloyd Dupont" <net.galador@ld> wrote in message
news:uc**************@TK2MSFTNGP14.phx.gbl... 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

Jan 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mACKnIFE | last post by:
Hi list! I've just finished reading the nice book: "Data Modeling and Relational Database Design Volume 1 - Student Guide", by Jan Speelpenning, Patrice Daux and Jeff Gallus, published by Oracle...
4
by: Daniel Ladd | last post by:
Hi, I have a problem with a conceptual graph in c++. I have a oist of structures like this: typedef struct Conceptual { char* Name;//Rappresenta la parola da mettere nel grafo Conceptual* Next;...
3
by: M Davidson | last post by:
Hello all, Thank you in advance for any guidance. (The standard form/subform won't work because my users will mess up and not enter a value for a category. I don't mean to speak ill of...
1
by: kuhni | last post by:
Hi everybody! Writing this time, I'm really desperate. Basically, I have a conceptual problem of how to solve a certain "problem" in MS Access 97. General objective: In order to categorise...
0
by: shirsoft | last post by:
I having some conceptual prob switching to c# I want to make a bitmap obj, and pass it to my func which will actually set its width, height and data ptr. But i am at loss as to how to do it ...
0
by: omyomyomy | last post by:
i have been set a task which i having problems with. i have to carry out the task of: The task is expected to be completed before the end of the second laboratory session. A full account on...
3
by: M_Mann | last post by:
Hello, Pls excuse if you consider this off-topic. Conceptual artists seek programmers here. We are authors of "Exhibition of Living Managers" (MANAGEX, www.managex.info) which is is global...
12
by: RSH | last post by:
I am still trying to grasp the use of real world Objects and how to conceptualize them using a business scenerio. What I have below is an outline that I am wrestling with trying to figure out a...
6
by: cppnow | last post by:
Hello. I have a strange conceptual problem I'm trying to think about. I would like to build a library that allows the user to do the following: 1) User defined types: The user defines their...
13
by: AliRezaGoogle | last post by:
Dear Members, I have a problem in the concepts of Monit.Enter and Monitor.Exit (Before everything I should say that I know how to solve this problem by using Monitor.Wait and I do not need a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.