Allow xsp to support Chinese Characters

Source: Internet
Author: User
Today, we finally know how to make xsp correctly display Chinese characters. The answer is codebehind. Yes.
The following code was found when debugging a page today.
Public class codebehind_aspx: system. Web. UI. Page, system. Web. sessionstate. irequiressessionstate {
......
Protected override void frameworkinitialize (){
Base. frameworkinitialize ();
This. responseencoding = "gb2312 ";
This. contenttype = "text/html ";
This. tracemodevalue = system. Web. tracemode. sortbytime;
This. Request. validateinput ();
This. _ buildcontroltree (this );
}
.....
}
 
This class is not written by me but automatically generated by JIT Based on the aspx file I wrote. It overwrites the frameworkinitialize method.
In this method, this. responseencoding = "gb2312"; has been specified to use gb2312 encoding, So I think xsp can support
Chinese. Since codebehind is decided to be used, the page and code must be separated and written. Many people may not get used to codebehind in environments without.
(Programmers spoiled by Ms). Here I recommend that you use DW to write the ASPX page and use sharpdevelop to write the DLL. sharpdevelop. A good function is
During compilation, you can select what the target framework is. If you select mono1.1 as the target framework, it will use MCS for compilation.
 
Aspx code:
 
<% @ Page Language = "C #" contenttype = "text/html" responseencoding = "gb2312" inherits = "monocodebehind. Welcome" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "return window. Status = '☆★☆Welcome! ☆★☆';} "Href =" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "return window. Status = '☆★☆Welcome! ☆★☆';} "Href =" http://www.w3.org/1999/xhtml "> http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> mono codebehind </title>
</Head>
<Body>
<Form ID = "frm1" name = "frm1" method = "Post" runat = "server">
<Asp: Label id = "label" runat = "server"> </ASP: Label>
<P> China <p>
<Asp: textbox id = "text" runat = "server"/>
<P> <asp: button id = "but" runat = "server"/>
</Form>
</Body>
</Html>

Here I leave <p> China <p> for comparison

Then create a new project in sharpdevelop and set it to DLL and the target framework to use mono1.1.
DLL code:
/*
* Created by sharpdevelop.
* User: Root
* Date: 2006-10-12
* Time:
*
* To change this template use tools | options | coding | edit standard headers.
*/
Using system;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Namespace monocodebehind
{
Public class welcome: Page
{

// You must use protected to declare a component.
// Because the Web framework uses reflection for searching
// Protected component
Protected label Label = new label ();
Protected textbox text = new Textbox ();
Protected button but = new button ();
Protected override void oninit (eventargs E)
{

This. initcomponent ();
Base. oninit (E );
}

Private void initcomponent ()
{

This. Load + = new eventhandler (this. page_load );
This. But. Click + = new eventhandler (this. button_click );

}

Private void page_load (Object sender, eventargs E)
{
Label. Text = "I Am a label ";
Text. Text = "I'm testbox ";
But. Text = "I Am a button ";
Response. Write ("response. Write () China ");
}

Private void button_click (Object sender, eventargs E)
{
Text. Text = "the button is pressed ";
}

}
}

Compile the file and place the generated DLL in the bin directory at the same level as the aspx file.
Then start xsp settings -- root and so on.

See Chinese ~

 

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.