Asp. NET Learning notes 005--asp.net IsPostBack Secrets
Source: Internet
Author: User
Previously written courses are not attached to the source code, I am sorry!
In the course of the source code can add QQ request: 1606841559
Technical Exchange QQ1 Group: 251572072
Technical Exchange QQ2 Group: 170933152
You can also download it yourself:
ASP. NET Learning notes 005asp.net IsPostBack secrets. zip Http://credream.7958.com/down_20144364.html
1.IsPostBack is said in the class:
If the form is not committed, then IsPostBack is false and if the form submits IsPostBack is true
2. In class, by judging whether the submitted content is empty or empty string to judge, this is somewhat unreasonable, if backstage
When you need to receive an empty, or an empty string, there is a problem with this judgment.
3. Can add a field to solve:
Http://localhost:61248/WebSite1/Hello2.ashx?IsPostBack=true&UserName=UserName
4. Also, if you want to back up the submitted value, you can do so by replacing the form of the custom field
Then the class works:
/website1
Hello2.htm
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form action= "Hello2.ashx" >
<input type= "hidden" name= "IsPostBack" value= "true"/>
Name: <input type= "text" value= "@value" name= "UserName"/>
<input type= "Submit" value= "submitted"/>
@msg
<!--
The server only has the name attribute, and if the Name property repeats, it will only submit the first
ID is used for DOM
-->
</form>
</body>
---------------------------------------------------------------------------
Hello2.ashx
<%@ WebHandler language= "C #" class= "Hello2"%>
Using System;
Using System.Web;
public class Hello2:ihttphandler {
public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "text/html";
//**********************************************
String IsPostBack =context. request["IsPostBack"];
if (IsPostBack = = "true") {
Context. Response.Write ("Submit Entry");
Msg =usernmae+ "--hello credream";
}else{
Context. Response.Write ("direct entry");
Usernmae = "";
msg = "";
}
When direct access is http://localhost:61248/WebSite1/Hello2.ashx, because there are no arguments behind it, so this time,
Show direct entry, when, fill in the content of the time, because there are parameters behind, so is submitted into the
Http://localhost:61248/WebSite1/Hello2.ashx?IsPostBack=true&UserName=UserName
String FullPath = context. Server.MapPath ("hello2.htm");//Get File Full path
String content = System.IO.File.ReadAllText (fullpath);//Get file Full
Content. Replace ("@value", Usernmae);
Content. Replace ("@msg", msg);
Direct access to this file will also be invoked
Context. Response.Write (content);
}
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.