Construction site using ASP.NET Community Starter Kit

xiaoxiao2021-03-06  22

Construction site using ASP.NET Community Starter Kit

Translation: Liu Haidong

The following content is translated from the BUILDING Websites with the ASP.NET Community Starter Kit by K. Scott Allen and Cristian Darie for Packt Publishing, the following is the book's book, detail how to extend CSK to increase the FAQ function. If you want to know ASP.NET Community Starter Kit details, you can go to www.asp.net to browse and download, it is a free open source project. If you want to build a robust and flexible ASP.NET website, CSK will be a good Point of departure.

Create a new module

Every community site will have different needs to be implemented. Although itself has a lot of flexibility, you can add customized additional features on this high-quality website. In this article, we will detail how to add a new feature FAQ (Frequently Asked Questions) in an existing framework and how to connect with the existing modules.

Before you really start, let you first, CSK is a project constantly modified and upgraded, so before you add new modules, first go online to find out if you have implemented this feature, or pay attention to whether CSK has added new Features.

Module design

Before you implement a module for CSK, you must first understand what you have to increase, and then determine which modules have been made by CSK to implement this feature.

First let us collect a general list of FAQ:

l A FAQ consists of a problem, an answer, a description or presentation, and some related references.

l Community members can review a comment or rating for a question, reminding when there is a new issue,

l If the moderator agrees, community members can post new questions.

You can of course only list the questions and answers in an HTML file, but then limit the user's interactive operation (comment, rating, email, etc.)

In the database included with the CSK, there is a table community_contentpages, which contains most of the information of the community page such as the author, browsing count, and a presentation. Since the answer to FAQ-related answers, reference links and other properties, we add a table community_faqs:

Then we can create classes that save FAQ information. In the following figure, the FAQInfo class inherits from ContentInfo, which can save most of the attributes of the general content information item. Every module has a Utility class to read, add, and edit content. So we have to create a FAQUTILITY class for FAQ modules.

We also have to create classes used by the Code-BEHIND page to display and edit FAQ. CSK is a different interface to display different pages by SkinnedCommunityControl. The CSK also includes other base classes that implement common functions, which can be used to increase (ContentAdditPage), and the contents, the following, shown inheritance relationships.

In addition, we also need to create classes inherited from WebControl to display FAQ content. Typically, each attribute is displayed in different controls, and the control can be displayed with the most suitable style. The following figures show these elements that will eventually be used in this module, which are ultimately inherited from WebControl.

Module creation process

The process of building a module we will use the bottom up to bottom, start from the database, and end the interface and the theme setting of the performance layer. We will keep the name model that has been agreed in CSK, keeping the style of other modules. For example, in the module of the book, you should read the information from the Community_books table, then the corresponding class is BookInfo. In this way, we use a table called Community_FAQS, called FAQINFO. Of course, you might want to add unique indication to prevent this module in the future CSK. For example, you work in ABC, then this table name can be called Community_ABCFAQS to reduce the name conflict that may occur in the future.

We will use the following steps to build a FAQ module. You can refer to these steps to build your own modules:

1. Create a new table (Community_faqs) to save the additional field information of the new module,

2. Create a stored procedure for adding, editing,, and selecting a FAQ, and another store procedure from all FAQs from a given range.

3. Create a maintenance stored procedure to initialize the FAQ module by populating community_pagetypes and community_namedpages tables.

4. Create a class of FAQINFO to save a FAQ information,

5. Creating a class of FAQUTILITY Classes to invoke the stored procedures related to the FAQ in front by accessing the database.

6. Create controls inherited from WebControl displays different fields, called FAQQuestion, Faqinro, Faqanswer, FaqReference, and FaqEditContent

7. Create a class inherited from SkinnedCommunityControl to include the logic behind the display page created next step. These classes are called AddFAQ, Editfaq, FAQSECTION, and FAQ

8. Create a new module to display the page, including FAQS_ADDFAQ.ASCX, FAQS_FAQSECTION.ASCX, FAQ_FAQ.ASCX. We will use FAQS_ADDFAQ to add and edit FAQ. In addition, you have to create default interface files, such as Robotics and Professional topics in a communityes / common / themes / defalult / skins / contentskins directory.

9. Create CSS files and topics related CSS files that define the module page style and put them in Communities / Common / Themes / Defalult / Styles.

Each step will be explained in detail below.

Community_faq table

Most modules share information such as titles, descriptions and browsing counts in the Community_ContentPages table. Additional information for this FAQ module needs to be added another table. For example, we can put FAQ's problem in the page_title field, and the introduction of FAQ is placed at the page_description field. In addition, we also need to store information such as FAQ answers and additional reference indexes, so create the table below:

Create Table [Community_faqs]

[FAQ_CONTENTPAGEID] [INT] NOT NULL,

[FAQ_answer] [NTEXT] NOT NULL,

[FAQ_REFERENCE] NULL,

Constraint [PK_COMMUNITY_FAQS] Primary Key Clustered

(

[FAQ_CONTENTPAGEID]

),

ConsTRAINT [fk_community_faqs_community_contentpages]]

Foreign Key

(

[FAQ_CONTENTPAGEID]

References [Community_ContentPages] ([ContentPage_ID]

) On delete cascade

It can be seen that the name of the table and the data type and other modules in the CSK are consistent, such program habits are difficult to do in China.

We store the FAQ's answer and the reference index field is NTEXT type, which is to support large data volume (up to 1GB). Also note that FAQ_answer is a necessary field and FAQ_REFERENCE can be null. Our primary key (FAQ_CONTENTPAGEID) is associated with additional content in the Community_ContentPages table. Another detail to note is the use of foreign bonds (cascade deletion), guaranteed data associated, and saves program code.

CSK deletes records in the Community_ContentPages table using a stored procedure called Community_ContentPageSdeleteContentPage (too long). When this stored procedure deletes the record, the server automatically deletes the corresponding record in the FAQ table according to the foreign key.

Increase stored procedure

Below we have to do is to establish, edit, read a single, read multiple recorded stored procedures, and no SQL code will appear in the code. From encapsulation and security, this is a good habit.

Community_faqsaddfaq

Below is a stored procedure for adding a new FAQ record. We don't need to fill a value for each field in the two tables. For example, we don't need to populate the contentpage_viewcount column (default is 0), and you don't need to fill in the date in ContentPage_Datecomment.

Create Procedure Community_faqsaddfaq

(

@communityID INT,

@sectionID INT,

@username nvarchar (50),

@topicid Int,

@question nvarchar (100),

@Introduction NVARCHAR (500),

@metadescription nvarchar (250),

@metakeys nvarchar (250),

@ModerationStatus Int,

@answer ntext,

@Reference NText

)

AS

Declare @ContentPageId Int

Declare @Pagettype Int

Set @Pagtype = dbo.community_getpageTypeFromName ('FAQ')

Declare @Userid Int

Set @userid = dbo.community_getuserid (@CommunityID, @USERNAME);

Begin TRAN

Exec @ContentPageId = Community_AddContentPage

@CommunityID,

@sectionID,

@ @Userid,

@Question,

@INTRODUCTION,

@metadescription,

@metakeys,

@Pagetype,

@ModerationStatus,

@topicid

INSERT Community_faqs

(

FAQ_CONTENTPAGEID,

FAQ_answer,

FAQ_REFERENCE

)

Values

(

@ContentPageID,

@ Answer, @ reasonnce

)

Commit TRAN

Return @ContentPageID

Note that the UDF (User Defined Function) provided by two CSKs, the first UDF retrieves page type, each module in the CSK has a unique page type. The second stored procedure is retrieved by the Community and the username.

Since we have to insert records in two different tables, transactions are used here to ensure atomicity of operation. The insert record in the Community_ContentPages table is done by calling the communit_addcontentpage stored, putting the problem as the @TITLE parameter, introduces the @Testle parameter. The addContentPage is executed after returning the primary key value of the new record, which is used to new records in Community_FAQs.

All new recorded stored procedures in CSK must return to the primary key value as a result.

Get a new contentPageID value is useful in the upper layer of the system, which we will see when you write the data to the component.

Community_faqseditfaq

This parameter required for modifying the stored procedures for existing FAQ records is much less than before. Because some fields will not be modified again after we add the record, such as the area number, etc. The code is as follows:

Create Procedure Community_FAQSEDITFAQ

(

@communityID INT,

@ContentPageID INT,

@username nvarchar (50),

@topicid Int,

@question nvarchar (100),

@Introduction NVARCHAR (500),

@metadescription nvarchar (250),

@metakeys nvarchar (250),

@answer text,

@Reference Text

)

AS

Declare @Userid Int

Set @Userid = dbo.community_getuserid (@CommunityID, @username)

EXEC Community_EditContentPage

@ContentPageID,

@ @Userid,

@Question,

@INTRODUCTION,

@metadescription,

@metakeys,

@topicid

Update Community_FAQs Set

FAQ_ANSWER = @answer,

FAQ_REFERENCE = @Reference

Where faq_contentPageId = @ContentPageID

Here we once again used the stored procedure community_contentpages in the CSK, then update Community_FAQs with Update's SQL. Compared to the new FAQ stored procedure, there is no transaction here to ensure the atomicity of the update operation. We follow the models already established in CSK, which do not use transactions here. Perhaps the designer thinks that the possibility of updating the failure is much smaller than new, reducing unnecessary resource locks to improve system data throughput.

Community_faqsgetfaqs

The stored procedure to be written is to return all FAQ records for a given range in a community. This stored procedure named community_getpagedsortedContent, adds parameters for the FAQ column on the original basis, and sorted with indexid.

Create Procedure Community_faqsgetfaqs

(

@communityID INT,

@username nvarchar (50),

@sectionID INT,

@PageSize Int,

@PageIndex Int,

@Sortorder nvarchar (50)

)

AS

Declare @currentdate datetime

Set @currentdate = getcdate ()

SELECT

Null FAQ_answer,

Null FAQ_REFERENCE,

CONTENT. *

From

DBO.COMMUNITY_GETPAGEDSORTEDCONTENT

(

@CommunityID,

@Username,

@sectionID,

@currentdate,

@Sortorder,

@PageSize,

@PageIndex,

DEFAULT

Content

ORDER BY

IndexID

This stored procedure uses two techniques that reduce code and future maintenance. First, we used content. * As the result of the return, and the stored procedure in the CSK was also used. In terms of efficiency, retrieving all columns allow databases to align which columns are needed to return more efficient. Moreover, the designer here is better than maintaining maintenance. If the structure of Community_ContentPages will be modified in the structure of Community_ContentPages, it is not necessary to modify or test the relevant stored procedure.

The second is to point out two empty columns (FAQ_answer and FAQ_Reference) of the result set. Later we will write a FAQINFO component to save multiple records from this stored procedure and a single record of a stored procedure. Since we want to use the same component to implement these two operations, we have to populate all columns. Because these two columns may take a lot of space, and will not be displayed in the statistical list of FAQ, so we use null values.

Community_faqsgetfaq

This stored procedure we have to use a separate record and other related features. It also needs to increase the access count of this page and tell the user to start reading the page. These tasks are completed by performing the CSK's Community_ContNetPageStrackstats process, the entire process code is as follows:

Create Procedure Community_faqsgetfaq

(

@communityID INT,

@username nvarchar (50),

@ContentPageID INT

)

AS

Declare @Userid Int

Set @Userid = dbo.community_getuserid (@CommunityID, @username)

- Update ViewCount and Hasread Stats

EXEC Community_ContentPagestrackstats @Userid, @contentpageID

Declare @currentdate datetime

Set @currentdate = getcdate ()

SELECT

FAQ_answer,

FAQ_REFERENCE,

CONTENT. *

From

DBO.COMMUNITY_GETCONTENTITEM

@CommunityID,

@ @Userid,

@currentdate) Content

Join Community_FAQs (NOLOCK)

On ContentPage_ID = FAQ_CONTENTPAGEID

WHERE

CONTENTPAGE_ID = @ContentPageID Note Because you want to display the details, we read the actual value of the FAQ_answer and the FAQ_Reference column. Here we use the NOLOCK option when Join Connect Community_FAQs, which will allow us to perform dirty readings without any warning tips. (Related to the database lock mechanism)

Initialization FAQ module

Each community module has a maintenance stored procedure for populating the information setting content of the data in the database. For example, we must register the page type by adding a record in Community_PageType: A message is about the page displaying the FAQ list, and the other is a page that displays a single FAQ details. In order to follow the CSK consistent naming rules, we call this stored procedure_maintenanceinitializefaqs, some of which are extracted as follows:

IF not exists (Select * from community_pagetypes

Where pagetype_name = 'faq section')

Begin

INSERT Community_Pagetypes

(

PageType_name,

PageType_Description,

PageType_pagecontent,

PageType_InsectionType,

PageType_ServiceSelect

)

Values

(

'FAQ Section',

'Contains FAQS in a Question and answer style format',

'Aspnet.Starterkit.communities.faqs.faqsection',

1,

'Community_faqsserviceSelectElectr'

)

End

Else

Print 'Warning: The FAQ Module Has Already Been Registered.'

Since the CSK caches the data of Community_NamePages so only the data will only be read. If you make modifications in these tables, you need to restart the web program to make the changes take effect.

This maintenance stored procedure also needs to register a static display page for important use of new modules, including new and editing pages, and you must use the identical name as you want to create as registration information as registration information.

Below is the relevant part of the code:

IF not exists (SELECT * home "_namedpages

Where namedpage_path = '/ faqs_addfaq.aspx')

Begin

INSERT Community_namedpages

(

Namedpage_name,

Namedpage_path,

NamedPage_PageContent,

Namedpage_title,

NamedPage_Description,

Namedpage_sortorder,

Namedpage_isvisible,

NamedPage_Menuid

)

Values

(

'Addfaq',

'/Faqs_addfaq.aspx',

'Aspnet.starterkit.communities.faqs.addfaq',

'Add faq',

'Enables Users to Add A New FAQ',

0,

1,

0

)

End

Else

Print 'Warning: /faqs_addfaq.aspx Has Already Been Registered

as a namedpage. '

Where the NamedPage_PageContent parameter is the full path to the Code-Behind class to use when CSK calls the static page: aspnet.starterkit.communities.faqs.addfaq. FAQ component

FAQInfo

All C # codes in all FAQ modules will be placed in the engine / modules / faqs directory. First add Helper classes within a directory of Components. Each CSK module should be placed in different namespaces, that is, after ASPNET.STARTERKIT.COMMUNITIES, add the module name as a qualified.

Using system;

Using system.data.sqlclient;

Namespace aspnet.starterkit.communities.faqs

{

Public Class Faqinfo: ContentInfo

{

Public FAQInfo (SqlDataReader DR): Base (DR)

{

IF (DR ["FAQ_answer"]! = dbnull.value)

{

_Answertext = (string) DR ["faq_answer"];

}

IF (DR ["faq_reference"]! = dbnull.value)

{

_ReferenceEutExt = (string) DR ["faq_reference"];

}

}

Public String Answertext

{

Get {return_answertext;

Set {_answertext = value;}

}

Public String ReferenceText

{

Get {return_reference;

Set {_referenceExt = value;}

}

Public String QuestionText

{

Get {return base.title;}

Set {base.title = value;

}

Public String Introtext

{

Get {return base.briefdescription;

Set {base.briefDescription = value;

}

PRIVATE STRING_ANSWERTEXT;

Private string _reference;

}

}

An instance of a SqlDataReader class is required when the FAQINFO class is initialized. In our next class, there will be data accessed code to create a SqlDataReader.

FAQUTILITY

According to the coding convention in CSK, we will put the process of data accesses in a static method of a Utility class. There is a static method corresponding to each of the stored procedures related to the FAQ. (In addition to the stored procedure for system maintenance, it is only used when the site is initialized). Each static method requires the corresponding parameters to be delivered to the stored procedure.

Here are the method of addFAQ:

Public Static Int AddFAQ

String username,

INT SectionID,

Int Topici,

String Question,

String Introduction,

String Answer,

String Reference,

INT MODERATIONSTATUS)

{

SqlConnection Conportal = New SqlConnection

CommunityGlobals.connectionstring;

Sqlcommand cmdadd = new sqlcommand

"Community_faqsaddfaq", Conportal); cmdadd.commandtype = commandtype.storedProcedure;

Cmdadd.Parameters.add ("@ return_value",

Sqldbtype.int) .direction =

ParameterDirection.ReturnValue;

cmdadd.parameters.add ("@ CommunityID",

CommunityGlobals.communityID;

Cmdadd.Parameters.Add ("@ sectionID", sectionID;

Cmdadd.Parameters.Add ("@ username", username);

Cmdadd.Parameters.Add ("@ TopiciD", Topicid;

Cmdadd.Parameters.Add ("@ Question", Question;

Cmdadd.Parameters.Add ("@ @ @Troduction", Introduction;

cmdadd.parameters.add ("@ metadescription",

ContentPageutility.calculateMetadescription (Introduction));

cmdadd.parameters.add ("@ metakeys",

ContentPageutility.calculatemetakeys (Introduction));

Cmdadd.Parameters.Add ("@ modelationstatus", modelationstatus);

Cmdadd.Parameters.Add ("@ Answer", SqldbType.nText);

Cmdadd.Parameters.Add ("@ reason", sqldbtype.ntext);

Cmdadd.Parameters ["@ answer"]. value = answer;

Cmdadd.Parameters ["@Reference"]. Value = Reference;

Conportal.open ();

cmdadd.executenon query ();

Int result = (int) cmdadd.parameters ["@ return_value"]. value;

Searchutility.AddSearchkeys (Conportal, SectionId, Result,

Question, Introduction);

Conportal.Close ();

Return Result;

}

Note that the SearchUtility class is called inside the AddFAQ method generates a query keyword related to the content, and it also returns the unique marker of the new object. One improvement here CSK needs to be done is to add TRY Catch Finally in the code to ensure the CLOSE method of executing the database connection. Although the possibility of abnormalities is small, for a large-capacity community website, you cannot withstand the performance of the waste of a waste of database connections.

The other two methods in FAQUTILITY are getFAQs and getfaqinfo. Getfaqs loops in SqlDataReader and returns an ArrayList of a faqinfo object, while GetFaqinfo only returns a FAQInfo object that is filled by a record in the database.

Public Static ContentInfo getfaqinfo (String UserName, int ContentPageID)

{

FAQINFO FAQ = NULL;

SqlConnection Conportal = New SqlConnection

CommunityGlobals.connectionstring;

SQLCommand cmdget = new SQLCOMMAND (

"Community_faqsgetfaq", Conportal;

Cmdget.commandtype = commandtype.storedProcedure;

cmdget.parameters.add (

"@communityid", communityglobals.communityID;

Cmdget.Parameters.Add ("@ username", username;

cmdget.parameters.add ("@ ContentPageID", ContentPageId;

Conportal.open ();

SqlDataReader DR = cmdget.executeReader ();

IF (Dr.Read ())

FAQ = New FAQINFO (DR);

Conportal.Close ();

Return FAQ;

}

Public static arraylist getfaqs (String Username, Int SectionID,

INT PageSize, Int pageIndex,

String Sortorder)

{

SqlConnection Conportal = New

SqlConnection (CommunityGlobals.Connections;

SQLCommand cmdget = new sqlcommand ("Community_faqsgetfaqs",

Conportal);

Cmdget.commandtype = commandtype.storedProcedure;

cmdget.parameters.add ("@ CommunityID",

CommunityGlobals.communityID;

Cmdget.Parameters.Add ("@ username", username;

Cmdget.Parameters.Add ("@ sectionID", sectionID;

Cmdget.Parameters.Add ("@ pagesize";

Cmdget.Parameters.Add ("@ pageindex", pageindex);

Cmdget.Parameters.Add ("@ Sortorder", Sortorder);

ArrayList FAQs = New ArrayList ();

Conportal.open ();

SqlDataReader DR = cmdget.executeReader ();

While (Dr.Read ())

FAQs.Add (New Faqinfo (DR));

Conportal.Close ();

Return FAQs;

}

The more important point here is that getfaqinfo uses the above-specific parameter list. This method will be called through other proxy classes in the class framework. The parameters must be consistent. When we write the content page, you will see how it is work.

Our data access layer is now completed. If you have created a module in this way, you can already start compiling and resolve errors. You can consider writing a driver page to test 4 static methods in FAQUTILITY and check if the results in Table Community_FAQs and Community_ContentPages are correct. FAQ WebControls

Dividing the display content into several smaller controls in the CSK. For example, in Engine / Framework / ContentPages / Controls directory, you will see a control (file name title.cs) that displays the title, and the controls of the content summary (briefscription.cs). We need to add two specific controls for FAQ, a display answer and reference, another link to the authorized user to display the editing content.

FAQANSWER and FAQREFERENCE

All controls at this layer are inherited from the .NET Framework's WebControl control. We only need to simply set the CSSClass property of the control, get the text you want to display from the current HTTPContext, and then redouble the renderContents method to write the text.

The following control will be created in Engine / Module / FAQS / Controls, used to display FAQ answers and references:

Using system;

Using system.Web;

Using system.Web.ui;

Using system.Web.ui.webcontrols;

Using aspnet.starterkit.communities.faqs;

Using system.componentmodel;

Namespace aspnet.starterkit.communities

{

[Designer (TypeOf (ASPNET.STARTERKIT.COMMUNITIES.COMMUNITYDESIGNER)]]]]

Public Class Faqanswer: WebControl

{

Public FAQANSWER (): base ()

{

CssClass = "faqanswertext";

IF (Context! = NULL)

{

Object faqinfo = context.items ["contentinfo"];

IF (FAQINFO! = NULL)

{

_Text = (FAQINFO) FAQINFO) .answertext;

}

}

}

Public String Text

{

Get {return_text;}

Set {_text = value;}

}

Override protected void rendercontents

HTMLTextWriter Writer)

{

SectionInfo objsectionInfo =

(SectionInfo) Context.Items ["SectionInfo"];

Writer.write

CommunityGlobals.Formattext

ObjsectionInfo.allowhtmlinput,

ObjsectionInfo.id, _text));

}

Private string_text;

}

}

Please note that the previous control is in the ASPNET.STARTERKIT.COMMUNITIES.FAQS namespace, but is placed in the last layer namespace. This is because the interface files used by CSK points to ASPNET.STARTERKIT.COMMUNITIES. The following line marks specify the interface for the above control:

FAQREfrence control is very similar to FAQANSWER. Both overloaded the RnderContents method and converted and format the output text using the CommunityGlobal class class.

FAQEDITCONTENT

Each CSK module uses a control inherited from EditContent to display editing links for authorized users, allowing users to add, delete, move, comment, and control content. What we have to do is set to set the appropriate URL attribute. The logic judgment in the base class determines when to display the correct link. All movements are completed in the creation process of class:

Public FaqEditContent ()

{

IF (Context! = NULL)

{

PageInfo PageInfo = (pageInfo) Context.Items ["PageInfo"];

INT contentPageId = pageinfo.id;

AddURL = "FAQS_ADDFAQ.ASPX";

Editurl = String.Format

"FAQS_EDITFAQ.ASPX? ID = {0}",

ContentPageID);

DeleteURL = String.Format

"ContentPages_DeleteContentPage.aspx? Id = {0}",

ContentPageID);

MoveURL = String.Format

"ContentPages_MoveContentPage.aspx? Id = {0}",

ContentPageID);

CommentURL = String.Format

"Comments_addcomment.aspx? Id = {0}",

ContentPageID);

ModerateURL = "Modression_ModeRATESECTION.ASPX";

}

}

Content class

In the traditional ASP.NET program example, the content class is a code-behind file. Since CSK allows users to make a higher level of customization, we will not be able to keep the window interface and code to keep synchronization with IDE. There is an uncertain association between them because each code is to support multiple window files in different interfaces. So we have to manually maintain page controls and event bindings. Although this task is not difficult but need to program the details, etc.

We have four content classes to implement:

l FAQ: Display a FAQ record

l FAQSECTION: Display a FAQ list

l Addfaq: Enter the content of FAQ

l Editfaq: Modify the content of FAQ

The number of code required to write a content class may differ. If we use the ContentItemPage and ContentPage classes in CSK, we only need to write very little code, you can display the FAQ and FAQ lists. Let's take a look at these two classes first.

FAQ and FAQSECTION

Public Class FAQSECTION: ContentListPage

{

Public FAQSECTION (): Base ()

{

SkinFileName = _skinfilename;

GetContentItems = _GetContentItems;

}

String _skinfilename = "faqs_faqsection.ascx";

GetContentItemsDelegate _GetContentItems = New getContentItemsdeLegate (FAQUTILITY.GETFAQS);

}

Here, we need to set the SkinFileName property to specify the actual interface file name. All controls inherited from SkinnedCommunityControl (basetes of ContentListPage) require this step to load the appropriate file.

When we write the data access method of the faqutility class, we mentioned that the need to create a proxy method is called by getContentItemsDelegate. This agent method will be read and display FAQ in the specified area in the base class. Follow this mode, when the FAQ class is initialized, FAQS_FAQ.ASCX is specified as the interface file and point the proxy method to FAQUTILITY.GETFAQ to call when it is required.

AddFAQ and EditFAQ

These two categories have a certain difficulty. Because methods used to add and modify content can be used in each module, and there is no base class to inherit to reduce workload. Instead, we need to find controls for the module to read and set values, and respond to user events trigger relevant data access processes.

Before implementing these features, we must first plan the controls for input and display on the page:

l Textbox: for FAQ issues

l Textbox: used for FAQ introduction

l TopicPicker: Select the topic in the FAQ list

l HTMLTextbox: used for FAQ answers

l HTMLTextBox: used for FAQ reference

In addition, we also need 5 corresponding controls to display FAQ, such as the FAQANSWER written in front to display the answer. The following is an example of the creation method of EditFAQ:

Public editfaq (): Base ()

{

SkinFileName = _skinfilename;

SectionContent = _SECTIONCONTENT;

THIS.SKINLOAD = New SkinLoadEventHandler (Skinlinefaq);

This.Preview = New PreviewEventHandler (PreviewFAQ);

THIS.SUBMIT = New SubmitEventHandler (Submitfaq);

}

In this method, the interface file name and sectionContent property used to display (later will be described later), and then associate the events in the base class with the response method.

ContentETETPAGE This event response function To include the following logical: loading interface file, handling the click and submission button of the Preview button.

Void SkinLoadFAQ (Object S, Skinlineadeventargs E)

{

TXTQUESTION = (TextBox) getControl (E.SKIN, "TXTQuestion);

// Continue Initializing All Controls with getControl...

}

As we discussed in the previous section, the CSK dynamic load interface (ASCX) file displays a specific topic. If you need to interact with the controls on the interface, you must first get the reference to the control instance. If we edit FAQ, you need to get the contents in the TextBox object. You can implement the getControl or getOptionalControl method in the SkinnedComunityControl base class, only the textbox that displays the problem is referenced here:

Protected Override Void OnLoad (Eventargs E) {

IF (! page.ispostback)

{

ContentPageId = Int32.Parse

Context.Request.QueryString ["ID"]);

FAQINFO FAQINFO =

FAQINFO) FAQUTILITY.GETFAQINFO

Objuserinfo.username, contentpageId;

EnsureChildControls ();

TXTANSWER.TEXT = FAQINFO.AnsWertext;

DROPTOPICS.SELECTEDTOPIPIPIPIPIPIPICID;

TXTINTRO.TEXT = FAQINFO.INTROTEXT;

TXTQUESTION.TEXT = FAQINFO.QuestionText;

TXTREFERENCE.TEXT = FAQINFO.Reference;

}

}

When the page is loaded, we need to get information that existing FAQ from the database. CSK will pass the ID of the content in the query parameter, and then we take out the ID to the GetFaqinfo method in the FAQUTILITY class. Once the FAQ object is obtained, it is displayed on the page.

Void PreviewFAQ (Object S, Eventargs E)

{

ObjsectionInfo.ENABLETOPICS)

TopicPreview.name = DROPTOPICS.SELECTEDITEM.TEXT;

QuestionPreview.Text = txtquestion.text;

IntroductionPreview.Text = txtintro.text;

Answerpreview.text = txtanswer.text;

ReferencePreview.Text = txtReference.Text;

}

When the user clicks on the preview button, we have to transfer all edited content to the preview control, where editing the content is rendered and displayed in the defined style. Make the author more effectively observe and design the appearance of the page in actual runtime. The ContentEdit class guarantees that the author has a preview panel and observe the result.

Void SubmitFAQ (Object S, Eventargs E)

{

IF (page.issalid)

{

// Get Topic

INT Topicid = -1;

ObjsectionInfo.ENABLETOPICS)

Topicid = int32.parse (DROPTOPICS.SELECTEDITEM.VALUE);

FAQUTILITY.EDITFAQ

Objuserinfo.username,

ObjsectionInfo.id,

ContentPageID,

Topicid,

TXTQuestion.text,

TXTINTRO.TEXT,

TXTANSWER.TEXT,

TXTREFERENCE.TEXT);

Context.Response.Redirect (CommunityGlobals.calculatePath)

String.Format ("{0} .aspx", contentpageId))));

}

}

The SUMBITFAQ event response function updates the content into the database via the FAQUTILITY class. Once the update ends, we send a prompt and leave the edit page, then redirect to the browse page to see the updated FAQ.

INT ContentPageID

{

Get {return (int) ViewState ["contentpageID"];

Set {ViewState ["ContentPageID"] = Value;}}

Textbox txtquestion;

TopicPicker DROPTOPICS;

Textbox txtintro;

HtmlTextBox txtanswer;

HtmlTextBox txtReference;

Displaytopic TopicPreview;

Title QuestionPreview;

Briefdescription;

FAQANSWER ANSWERPREVIEW;

FAQReference ReferencePreview;

String _skinfilename = "ferqs_addfaq.ascx";

String _sectionContent =

"Aspnet.starterkit.communities.faqs.faqsection";

}

The AddFAQ page is basically similar to the page of EditFAQ, just to increase the options for displaying content with different pages.

FAQ Page Content Skins

Our FAQ modules need to have 3 interfaces:

l Display the interface of a single FAQ detail

l Show interfaces of multiple FAQ lists

l Add or modify a FAQ interface

We must create these three interface files at least in the default topic directory. If you want to have different interfaces, you can continue to add additional theme interfaces. For new or modified FAQ pages that may be as follows:

Here you must determine the interface file name and match the assignment of the SkinFileName property in the content page class. Also pay attention to the control name, you must be the same as the parameter name used in the getControl method in the call class.

The easiest way is to start create an interface from an existing interface window because you still have to keep the same as the base class. We should still remember that our AddFAQ class is inherited from ContentAddPage. He needs to have some specific controls on the interface, such as a button called a PNLFormde panel and a button named btnadd. Let's take a look at the interface of FAQ_ADDFAQ:

<% @ Control%>

<% @ Register tagprefix = "community"

Namespace = "aspnet.starterkit.communities"

AskEMBLY = "ASPNET.Starterkit.communities"%>

Cssclass = "form_title"

Runat = "server"

ID = "SectionTitle1"

Name = "sectionTITION1" />

Use this form to add or edit an faq.

Class = "form_table">

FAQ Form

Question:

ControlTovAlidate = "txtquestion"

TEXT = "(Required)

Runat = "server"

ID = "RequiredFieldValidator1"

Name = "RequiredFieldValidator1" />

CssClass = "form_field"

Column = "40"

Runat = "Server">

...

The interface used to display the content is relatively easy to build, you only need to arrange the control according to the appropriate location. Here is the interface to display a separate FAQ:

<% @ Control%>

<% @ Register

Tagprefix = "Community"

Namespace = "aspnet.starterkit.communities"

AskEMBLY = "ASPNET.Starterkit.communities"%>

Class = "FAQ_TABLE">

>

ID = "displaytopic1"

Name = "displaytopic1" />

Name = "Title1" />



Posted by

Runat = "server" id = "author1"

Name = "author1" />

on

ID = "datecreated1"

Name = "datecreated1" />



ID = "Introduction1"

Name = "Introduction1" />

ID = "answer1" name = "answer1" />

ID = "refrence1"

Name = "reasonence1" />


Runat = "server" id = "Rating1"

Name = "Rating1" />

Text = "Notify Me When A New Comment IS Posted"

Runat = "server" id = "notify1" name = "notify1" />

ID = "comments1"

Name = "comments1" />

CommentText = "Add your comment"

EditText = "Edit this FAQ"

Deletetext = "delete this faq"

Runat = "server" id = "faqeditcontent1"

Name = "faqeditcontent1" />

In this interface, we use our own web control (including only FAQEDITCONTENT links displayed for a specific user). With these interface files, you only have the last step.

Module style

When you create a new interface and a web control, you want to identify the CSS name you placed in your code. We want to modify these CSS files when there is a new requirement in the module. Since the default CSS settings are not available in CSK, you need to define each module.

System integration

Now you can start and test new modules. The result of run is like the following graphics: summary

Creating a new module in CSK needs to interact with the existing architecture, so we first understand the overall architecture of the CSK. This article describes the CSK architecture and detail how to add a custom new module and programming mode and naming style you need to follow during the implementation.

转载请注明原文地址:https://www.9cbs.com/read-79610.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.035, SQL: 9