HtmlInputFile.OnPreRender メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HtmlInputFile.OnPreRender メソッドの意味・解説 

HtmlInputFile.OnPreRender メソッド

HtmlInputFile コントロールの PreRender イベント発生させます

名前空間: System.Web.UI.HtmlControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Friend Overrides
 Sub OnPreRender ( _
    e As EventArgs _
)
Dim e As EventArgs

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

パラメータ

e

イベント データ格納している EventArgs。

解説解説
使用例使用例

OnPreRender メソッドオーバーライドして、それぞれのカスタムHtmlInputFile コントロールに常に Title 属性追加されるようにする方法次のコード例示します。この例を正常に動作させるには、コンピュータの C: ドライブTemp というディレクトリ作成する必要があります

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls"
 Assembly="Samples.AspNet.VB"
 %>
<%@ Page Language="VB" AutoEventWireup="True"
 %>

<script runat="server">
  
  Sub Button1_Click(ByVal source As
 Object, ByVal e As EventArgs)

    ' Make sure the file was submitted.  
    If HtmlInputText1.Value = ""
 Then
      
      Span1.InnerHtml = "Error: You must enter a file name."
    
    ' Save the file 
    ElseIf Not (HtmlInputFile1.PostedFile Is
 Nothing) Then

      Try
        
        HtmlInputFile1.PostedFile.SaveAs("c:\\temp\\"
 & HtmlInputText1.Value)
        Span1.InnerHtml = "File uploaded successfully to: <b>c:\temp\"
 _
                        & HtmlInputText1.Value & "</b>
 on the Web server."

      Catch exc As Exception
        
        Span1.InnerHtml = "Error saving <b>c:\temp\"
 _
                        & HtmlInputText1.Value & "</b><br>"
 _
                        & exc.ToString() & "."
        
      End Try
      
    End If
    
  End Sub
  
</script>

<html>
  <head>
    <title>Custom HtmlInputFile OnPreRender Example</title>
  </head>

  <body>
    <form enctype="multipart/form-data"
          runat="server">

      <h3>Custom HtmlInputFile OnPreRender Example</h3>

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

      <p>
      Save as file name (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>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls"
 Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>

<script runat="server">

  void Button1_Click(object Source, EventArgs e)
  {
    // Make sure a file was submitted.
    if (HtmlInputText1.Value == "")
    {
      
      Span1.InnerHtml = "Error: You must enter a file name.";
      
    }
      
    // Save the file.
    else if (HtmlInputFile1.PostedFile != null)
    {  
      try
      {
        
        HtmlInputFile1.PostedFile.SaveAs("c:\\temp\\" + HtmlInputText1.Value);
        Span1.InnerHtml = "File uploaded successfully to: <b>c:\\temp\\"
 + 
                           HtmlInputText1.Value + "</b> on the Web server.";
               
      }
      catch (Exception exc)
      {
        
        Span1.InnerHtml = "Error saving <b>c:\\temp\\" +
                           HtmlInputText1.Value + "</b><br>"
 + exc.ToString() + ".";
        
      }
      
    }
    
  }
</script>

<html>
  <head>
    <title>Custom HtmlInputFile OnPreRender Example</title>
  </head>
  <body>
    <form enctype="multipart/form-data"
          runat="server">

      <h3>Custom HtmlInputFile OnPreRender Example</h3>
 
      Select File to Upload:
      <aspSample:CustomHtmlInputFileOnPreRender
        id="HtmlInputFile1"
        type="file"
        runat="server"
        name="HtmlInputFile1">

      <p>
      Save as file name (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>
<%@ 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>
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)>
 _
    Public NotInheritable Class
 CustomHtmlInputFileOnPreRender
        Inherits System.Web.UI.HtmlControls.HtmlInputFile

        Protected Overrides Sub
 OnPreRender(ByVal e As System.EventArgs)

            ' Call the base OnPreRender method.
            MyBase.OnPreRender(e)

            ' Add a Title attribute to the HtmlInputFile control.
            Me.Attributes.Add("title",
 "Click the Browse button to select a file to upload.")
        End Sub
    End Class

End Namespace
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class CustomHtmlInputFileOnPreRender
 : System.Web.UI.HtmlControls.HtmlInputFile
    {
        protected override void OnPreRender(System.EventArgs
 e)
        {
            // Call the base OnPreRender method.
            base.OnPreRender(e);
            
            // Add a Title attribute to the HtmlInputFile control.
            this.Attributes.Add("title", "Click
 the Browse button to select a file to upload.");
        }
    }
}
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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlInputFile クラス
HtmlInputFile メンバ
System.Web.UI.HtmlControls 名前空間
HtmlForm クラス
HtmlForm.Enctype プロパティ
Control.OnPreRender
Control.PreRender
その他の技術情報
HTML サーバー コントロール


このページでは「.NET Framework クラス ライブラリ リファレンス」からHtmlInputFile.OnPreRender メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHtmlInputFile.OnPreRender メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHtmlInputFile.OnPreRender メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HtmlInputFile.OnPreRender メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlInputFile.OnPreRender メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS