Reading Notes ASP. NET 2.0 Programming

Source: Internet
Author: User
Tags javascript extension connectionstrings

This book is good. I have read it several times and each time I have a new experience. The following are some experiences, mistakes and mistakes. You are welcome to criticize and correct them.
1 use the page base class
public class baseuipage: system. web. UI. page
{< br> Public baseuipage ()
{}< BR >}< br> use the page base class, reduce the number of Code duplicates. For example, rewrite the error handling method and share the basic class attributes.
Let me give two examples
1) rewrite the onerror method and redirect to the error page when an error occurs.
protected override void onerror (eventargs e)
{< br> server. Transfer ("~ /Error. aspx ");
}< br> Create a page inherited from baseuipage and create an error in the Code
throw new applicationexception (); or int A = 0; int B = 3; a = B/a;
2) Example of a permission system
[actions (permission. read)]
Public partial class quotareivewreport: baseuipage
{< br> Public quotareivewreport (): Base (systemmodule. reportpagebase) {}< BR >}< br> In the baseuipage of the base class, check whether the current user's role permission list includes the permissions required to execute the current page (quotareivewreport) (permission. Read), skip to the error page if not included.

2 web configuration
these settings are stored in an external file. You can save the external file locally. In the web. config uses appropriate references to include these files, such as web.

localhost. config file content



A permission management system, each time you create a project, you always need to copy some configurations to the web of the new project. config file. With this feature, you only need to copy the configured permission. config file to the root directory of the new project and specify the file name in Web. config, which greatly reduces the chance of errors.
you can set the connection string in the same way. In the web. config

localhostconnectionstrings. config external file content



If you modify the Web. the config file will cause the site to restart and modify localhostconnectionstrings. the config file will not cause the website to restart. Good readability.
similar to the configuration of WCF, it is also troublesome. It is also intended to reference external files in this way. Unfortunately, configsource is not supported in the WCF configuration. To use the WCF custom configuration file, you must rewrite the relevant methods.

3. Export a template
Export template, which will be used when you create a new project or a new project. You can use this wizard to create a template for an entire project or an item in the project.
A project usually has some common base classes. This feature can make the base class A template. When creating an item, select the corresponding template.

4. client callback
Screenshot to see how the client callback works

There are already many examples of code on the Internet.

5 Ajax is not just a client script Library
Ajax control toolbox
Timer, scheduled execution method. This requires the page class as a container. If there is no page container, you can select system. Timers. Timer.
Updatepanel defines the container control that is asynchronously refreshed with the server. It is used most often. Note that the scriptmanager control should be placed on the page. In addition, the fileupload and menu controls do not support asynchronous refresh in updatepanel.
Auto complete completed automatically
<Ajax: autocompleteproperties targetcontrolid = "statetextbox" enabled = "true" servicepath = "statelistws. asmx" servicemethod = "getmatchingstates"/>
Call the following method in the post code:
[Webmethod]
Public String [] getmatchingstates (string prefixtext, int count)
{
}
Using services in browsers and using JavaScript to call web services is much simpler than using JavaScript directly.
<Ajax: scriptmanager id = "scriptmanager1" runat = "server">
<Services> <Ajax: servicereference Path = "maplocformatter. asmx"/> </services>
</Ajax: scriptmanager>
Javascript extension, as shown in the following code, using JavaScript to create object-oriented types
Type. registernamespace ("mvphacks ");

6. visuizer)

For example, this is a string viewer,
This function is very useful in debugging and splicing SQL statement code strings. You can directly copy the code from here to the query analyzer to verify whether the SQL statement is correct.
You can also view the structure and data of a dataset table in dataset visualizer.
The other two skills have never been used. It is inconvenient to write code for debugging a project.

[Debuggerbrowsable (debuggerbrowsablestate. Collapsed)]
Public list <person> Children
{
Get {return _ children ;}
}
Or create a proxy class.
[Debuggertypeproxy (typeof (personproxy)]
Class person {}

7 viewstate
First look at the picture to deepen the impression

There is a famous saying on the Internet: Do not use static variables on the page
To save the status of the current user operation, such as updating the action or creating a new task, use viewstate.
There are still high people on the Internet, which is super simple: The viewstate attribute is used
By declaring a feature in the properties of the page, you can learn how to use the feature to make it a viewstate.
[Viewstateproperty ("userid")]
Protected int viewstate_userid {Get; set ;}
Or
[Viewstateproperty]
Protected int viewstate_userid {Get; set ;}
Improves viewstate performance. ASP. NET 2.0 compresses viewstate to improve viewstate performance.
Changes the storage location of viewstate and overwrites the storage destination of viewstate to improve page performance.

8 parameterization of in expressions
To enable in to support parameters, you need to write a function to parse this parameter and break it into comma-separated strings or values.
Select employeeid, lastname from employees
Where employeeid in (@ List)

To prevent SQL injection attacks, filter user input strings. For example, replace comma with double quotation marks to check SQL keywords.
A better way is to use query parameters. Although debugging is troublesome, it is difficult to find SQL errors.
The compromise between my code generator is that we can generate the join SQL statement and the Dal code of the query parameter at the same time. We generally use the Dal code of the query parameter, if it is necessary to debug the final SQL statement, use the concatenated SQL statement Dal. After the debugging is complete, change the Dal code of the query parameter.

9 use the rdlc report control on the ASP. NET page
Add reference in Web. config
<Add tagprefix = "rsweb" namespace = "Microsoft. Reporting. webforms" assembly = "Microsoft. reportviewer. webforms, version = 9.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a"/>
Drag a widget to the page
<Rsweb: reportviewer id = "RPT" runat = "server" width = "100%" Height = "400px"
Font-names = "verdana" font-size = "8pt">
<Localreport>
<Datasources>
</Datasources>
</Localreport>
</Rsweb: reportviewer>
Post Code
Rpt. localreport. reportpath = appdomain. currentdomain. basedirectory + "/report. rdlc ";
String project = ddlproject. selectedvalue;
Datatable TBL = reportdal. getreport (project );
If (TBL! = NULL)
{
Rpt. localreport. CES. Clear ();
Rpt. localreport. CES. Add (new Microsoft. Reporting. webforms. reportdatasource ("Report", TBL ));
Rpt. localreport. Refresh ();
}
Rpt. localreport. Refresh ();
}
It is much easier to deploy than a crystal report. If you have any problems, go to the installation directory of vs ideto find reportviewer.exe,
Execute the installation on the deployment machine.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.