AutoPostBack哪去了?
从前使用web
Form开发的程序员经常会问到AutoPostBack跑哪去了?使用IDE,并且在AutoPostBack打个勾是非常容易的。而正是因为容易使
用,所以大多开发人员不会去想AutoPostBack是怎样的机制。实际上,如果你选择AutoPostBack,则DropDownList会被添加
一个引发javascript事件的onchange属性,导致DropDownList所在的form被提交。这个过程在MVC中必须手动实现,但是也
非常简单,我下面的代码用两种方式实现这点,第一段代码中的方式通过object作为参数来设置html的属性,另一段代码使用jQuery来实现同样的
效果。毫不谦虚的说,我已经将DropDownList在form中的大部使用都写出来了,下面是第一种方法:
<%
using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "TheForm" })){%>
<%
= Html.DropDownList(
"CategoryID",
(SelectList) ViewData["Categories"],
"--Select One--",
new{
onchange = "document.getElementById('TheForm').submit();"
})%>
<%
}%>
......
水仙花数:一个三位整数各位数字的立方和等于该数本身就称该数为水仙花数,水仙花数共有4个,分别为:153、370、371、407( 例如:1^3 + 5^3 + 3^3 = 153 )。我写的代码如下,你有其他的实现代码也可以发表评论。
int i, m,n,k;
for (i = 100; i < 1000; i++)
{
//取得百位数
m = i / 100;
//取得十位数,这里也可以用n = (i%100)/10;
n = i/10%10;
//取得个位数
k = i % 10;
//打印输出水仙花数
if (m * m * m + n * n * n + k * k * k == i)
Response.Write(i + "<br />");
}
......
水仙花数:一个三位整数各位数字的立方和等于该数本身就称该数为水仙花数,水仙花数共有4个,分别为:153、370、371、407( 例如:1^3 + 5^3 + 3^3 = 153 )。我写的代码如下,你有其他的实现代码也可以发表评论。
int i, m,n,k;
for (i = 100; i < 1000; i++)
{
//取得百位数
m = i / 100;
//取得十位数,这里也可以用n = (i%100)/10;
n = i/10%10;
//取得个位数
k = i % 10;
//打印输出水仙花数
if (m * m * m + n * n * n + k * k * k == i)
Response.Write(i + "<br />");
}
......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Collections.Generic;
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;
using i_salesDAL;
using i_salesModels;
using i_salesBLL;
using MySql.Data.MySqlClient;
public partial class login : System.Web.UI.Page
{
Ss_users myUser;//实例化一个用户对象
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void btnlogin_Click(object sender, EventArgs e)
{
string name = this.txtname.Text;
string pwd = this.txtpwd.Text;
if (this.txtname.Text.Trim().Length == 0 || this.txtpwd.Text.Trim().Length == 0)
{
//如果用户名或者密码没有输入,提示用户
Page.RegisterStartupScript("", " ......
web.config
<customErrors mode="On" defaultRedirect="ApplicationErroy.aspx" >
<error statusCode="403" redirect="403.htm"/>
<error statusCode="404" redirect="404.htm"/>
<error statusCode="500" redirect="500.htm"/>
</customErrors>
Global.asax
<%@ Application Language="C#" %>
<mce:script runat="server"><!--
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
}
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
Exception erroy = Server.GetLastError();
string err = "出错页面是:" + Request.Url.ToString() + "</br>";
......
1:GridView 添加属性(是否删除,鼠标经过背景)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699f0'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
......
废话不说,直接代码部分代码摘抄自网上,在此想原作者表示感谢
1、服务端 uploadFile.ashx
<%@ WebHandler Language="VB" Class="UploadFile" %>
Imports System
Imports System.Web
Imports System.Web.HttpServerUtility
Imports System.IO
Imports System.Web.HttpRequest
Public Class UploadFile : Implements IHttpHandler
Private m_UploadPath As String = "~\Files\"
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
Dim responses As String = ""
Dim files As HttpFileCollection = context.Request.Files
If files.Count = 0 Then
'Response.Write("请勿直接访问本文件 ......
废话不说,直接代码部分代码摘抄自网上,在此想原作者表示感谢
1、服务端 uploadFile.ashx
<%@ WebHandler Language="VB" Class="UploadFile" %>
Imports System
Imports System.Web
Imports System.Web.HttpServerUtility
Imports System.IO
Imports System.Web.HttpRequest
Public Class UploadFile : Implements IHttpHandler
Private m_UploadPath As String = "~\Files\"
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
Dim responses As String = ""
Dim files As HttpFileCollection = context.Request.Files
If files.Count = 0 Then
'Response.Write("请勿直接访问本文件 ......