HtmlInputFile.OnPreRender Method

Raises the PreRender event for the HtmlInputFile control.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

protected public:
virtual void OnPreRender (
	EventArgs^ e
) override
protected void OnPreRender (
	EventArgs e
)
protected internal override function OnPreRender (
	e : EventArgs
)

Parameters

e

An EventArgs that contains event data.

If no encoding is specified for the Web page's HtmlForm control, the Enctype property is set to "multipart/form-data".

The following code example demonstrates how to override the OnPreRender method so that a Title attribute is always added to each custom HtmlInputFile control. For this example to work properly, you need to create a directory called Temp on your computer's drive C.

No code example is currently available or this language may not be supported.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<HTML>
  <HEAD>
    <title>Custom HtmlInputFile - OnPreRender - VJ# Example</title>
    <script runat=server>
void Button1_Click(Object source, EventArgs e)
{
    if (HtmlInputText1.get_Value().Equals("")) {
        Span1.set_InnerHtml("Error: you must enter a file name");
    }
    else if (HtmlInputFile1.get_PostedFile() != null) {
        String tempPath = Environment.GetFolderPath(Environment.SpecialFolder.
            InternetCache) + "\\";
        try {
            HtmlInputFile1.get_PostedFile().SaveAs(tempPath + HtmlInputText1.
                get_Value());
            Span1.set_InnerHtml("File uploaded successfully to:<br><b>"
                + tempPath + HtmlInputText1.get_Value()
                + "</b><br>on the Web server");
        }
        catch (Exception ex) {
            Span1.set_InnerHtml("Error saving file:<br><b>"
                + tempPath + HtmlInputText1.get_Value() + "</b><br>"
                + ex.ToString());
        }
    }
} //Button1_Click
    </script>
  </HEAD>
  <body>
    <form id="Form1" method="post" runat="server" enctype="multipart/form-data">

      <h3>Custom HtmlInputFile - OnPreRender - VJ# Example</h3>

      Select File to Upload:
      <aspSample:CustomHtmlInputFileOnPreRender
        id="HtmlInputFile1"
        type="file"
        runat="server"
        name="HtmlInputFile1">
      </p>

      <p>
      Save as filename (no path):
      <input id="HtmlInputText1"
        type="text"
        runat="server"
        name="Text1">
      </p>
      <p>
      <span id="Span1"
        style="font: 8pt verdana;"
        runat="server" />
      </p>
      <p>
      <input type="button"
        id="Button1"
        value="Upload"
        OnServerClick="Button1_Click"
        runat="server"
        name="Button1">
      </p>

    </form>
  </body>
</HTML>

No code example is currently available or this language may not be supported.
package Samples.AspNet.JSL.Controls;

public class CustomHtmlInputFileOnPreRender
    extends System.Web.UI.HtmlControls.HtmlInputFile
{
    protected void OnPreRender(System.EventArgs e)
    {
        // Call the base OnPreRender method.
        super.OnPreRender(e);
        // Add a Title attribute to HtmlInputFile.
        this.get_Attributes().Add("title", 
            "Click the Browse button to select a file to upload.");
    } //OnPreRender
} //CustomHtmlInputFileOnPreRender

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: