为usercontrol中的fileupload设置postback(用于updatepane中)

原创:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Upload.ascx.cs" Inherits="Upload" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<%@ Register TagPrefix="Joey" TagName="Upload" Src="~/Upload.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    
<title>Untitled Page</title>
</head>
<body>
    
<form id="form1" runat="server">
        
<asp:ScriptManager ID="ScriptManager1" runat="server" />
        
<div>
            
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                
<ContentTemplate>
                    
<Joey:Upload runat="server" ID="Joey1" />
                
</ContentTemplate>
            
</asp:UpdatePanel>
        
</div>
    
</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Upload : System.Web.UI.UserControl
{
    
protected override void OnLoad(EventArgs e)
    
{
        
base.OnLoad(e);
        ScriptManager manager 
= ScriptManager.GetCurrent(this.Page);
        
if (manager != null)
        
{
            manager.RegisterPostBackControl(
this.Button1);
        }

    }

    
protected void Button1_Click(object sender, EventArgs e)
    
{
        
if (this.FileUpload1.HasFile)
        
{
            
this.TextBox1.Text = "yes";
        }

        
else
        
{
            
this.TextBox1.Text = "no";
        }

    }

    
protected void Button2_Click(object sender, EventArgs e)
    
{
        
if (this.FileUpload1.HasFile)
        
{
            
this.TextBox1.Text = "yes";
        }

        
else
        
{
            
this.TextBox1.Text = "no";
        }

    }

}

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default5 : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
    }

}

posted @ 2008-03-15 23:01  N/A2011  阅读(572)  评论(0编辑  收藏  举报