There are many messy solutions on the Internet, such as setting up Web. config.
Thanks to the monkey for telling me the most common method is the front-end JS Chinese code escape () and backend decoding server. urldecode ()
In addition, if the advanced save option of the webpage is not UTF-8, change it. I have not tried any other encoding. In short, this encoding is successful.
Front-end:
- <% @ Page Language = "C #" autoeventwireup = "true" codefile = "ajaxluanma. aspx. cs" inherits = "testxc_ajaxluanma" %>
- <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <HTML xmlns = "http://www.w3.org/1999/xhtml">
- <Head runat = "server">
- <Title> Ajax Garbled text </title>
- <SCRIPT type = "text/JavaScript">
- // Enter the column number, column name, And monthnum to update the database.
- // If monthnum is "null", it indicates that the temporary table is to be updated.
- // If monthnum is not empty, update the template table based on the month and column number.
- Function callserver (colname, Col, monthnum)
- {
- Arg = escape (colname) + '|' + escape (COL) + '|' + escape (monthnum );
- <% = Clientscript. getcallbackeventreference (this, "Arg", "oncallback", null) %>;
- }
- // Callback function, prompt.
- Function oncallback (result, context)
- {
- Alert (Unescape (result ));
- }
- </SCRIPT>
- </Head>
- <Body>
- <Form ID = "form1" runat = "server">
- <Div>
- <Input type = "button" value = "OK" onclick = 'callserver ("column name", "column number", "blank"); '/>
- </Div>
- </Form>
- </Body>
- </Html>
Background:
- Using system;
- Using system. Data;
- Using system. configuration;
- Using system. collections;
- Using system. Web;
- Using system. Web. Security;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
- Using system. Web. UI. webcontrols. webparts;
- Using system. Web. UI. htmlcontrols;
- Public partial class testxc_ajaxluanma: system. Web. UI. Page, system. Web. UI. icallbackeventhandler
- {
- Private string result;
- Protected void page_load (Object sender, eventargs E)
- {
- }
- // Handle callback events
- Public void raisecallbackevent (string eventargument) // The parameter is a string passed from the foreground.
- {
- String [] ARGs = eventargument. Split ('| ');
- // Execute the business logic
- String arg0 = server. urldecode (ARGs [0]);
- String arg1 = server. urldecode (ARGs [1]);
- String arg2 = server. urldecode (ARGs [2]);
- If (arg2 = "null ")
- Result = "Update temporary table:" + arg0 + "and" + arg1;
- Else
- Result = "Update template table:" + arg0 + "and" + arg1;
- }
- // Return the callback result
- Public String getcallbackresult ()
- {
- Return result;
- }
- }
End