tags:

views:

97

answers:

1

hi, i am really trying to do this but i am failing to find a way.

here is the scenario, i got a blog module i made for my clients, because it is a repeatative task, so i all i have to do is to just upload it to new client and he can start blogging, but some clients need extra custom fields, let us say he wants to add a phone number for each article author, or extra reference, but i don't want to implement it for each client because it is a custom requirement.

now to do that i thought of creating a dynamic user control with this extra filed and this code in the user control for example

Blog bl = new Blog();
bl.ExtraRefrence = " http://www.something.com";

load it into the blog management panel, but what i want to do is to have the ability to let user control use the data context in the main blog editing page, what i mean is that the main page will have the insert command, so how i let main page insert command see the dynamic user control value without creating 2 Blog objects one in page and one in user control.

sorry if i am not clear, but seriously this killing me.

+1  A: 

Option 1
Make the field configurable.

Pseudo-code:

if client.HasExtraReference() then
   <asp:label text="<%= client.ExtrareferenceLabel %>" />
   <asp:textbox id="txtExtraReference" />
end if

and the in code-behind

Blog bl = new Blog();
bl.Content = ...
....
if client.HasExtraReference() then
    bl.ExtraRefrence = txtExtraReference.text;
end if

The HasExtraReference method could look you some config.

Option 2
If have multiple extra and variable number of fields you could add a ExtraBlogItem table.

BlogExtraItem
-------------
BlogExtraItemID int
BlogID int
ItemName Varchar(50)
ItemValue Varchar(250)

Add the items you wish in the page, and then pass a uniform List( Of BlogExtraItem ) parameter to the Blog.Insert Function

Eduardo Molteni
thanks man, but the thing is is that extra reference was an example, each client might have different requirement, what i want is some way to plug any dynamic extra new fields to the main blog insert function, or something like override for the insert function.
The problem is that the LINQ dataContext must be aware of the field in order to use and update them.
Eduardo Molteni
thanks alot man, but i think i have not been clear enough, it is no problem to implement the extra fileds in the user control, the thing is i want the Blog DB class to be in static class so i can use it from both user control and ASPX Page, i was able to make it in static class but the problem it doe not save the values neither of Page or user control, i think there is problem with Datacontext being a static class like thisnamespace Modules.Core.Blog{ public class DataAccess { public Blog InsertItem () { Blog b = new Blog (); return b; } }}
If you add a field to the database, you need to re-create the datacontext to be aware of the changes. That must be your problem. But .. If you implement it as a list of attributes (or items, like the example in Option 2), you have the same DB structure and no problems saving.
Eduardo Molteni
thanks again mate for answering me, it is not that DB is not updated, it is that even main blog Fields are not getting updated when i use the Blog class as static class, i have noticed the same thing with datacontext, if you call it from a static class, then it wil lnot work, i dont know what is going wrong here