ClientScriptManager.RegisterHiddenField メソッド
アセンブリ: System.Web (system.web.dll 内)
構文
Public Sub RegisterHiddenField ( _ hiddenFieldName As String, _ hiddenFieldInitialValue As String _ )
Dim instance As ClientScriptManager Dim hiddenFieldName As String Dim hiddenFieldInitialValue As String instance.RegisterHiddenField(hiddenFieldName, hiddenFieldInitialValue)
使用例
RegisterArrayDeclaration メソッドと RegisterHiddenField メソッドの使用方法を示すコード例を次に示します。この例では、配列と隠し値を登録し、配列の 2 つの値と隠し値の合計を計算する <input> ボタンの OnClick イベントを定義します。
<%@ Page Language="VB" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' Define the array name and values. Dim arrName As String = "MyArray" Dim arrValue As String = """1"", ""2"", ""text""" ' Define the hidden field name and initial value. Dim hiddenName As String = "MyHiddenField" Dim hiddenValue As String = "3" ' Define script name and type. Dim csname As String = "ConcatScript" Dim cstype As Type = Me.GetType() ' Get a ClientScriptManager reference from the Page class. Dim cs As ClientScriptManager = Page.ClientScript ' Register the array with the Page class. cs.RegisterArrayDeclaration(arrName, arrValue) ' Register the hidden field with the Page class. cs.RegisterHiddenField(hiddenName, hiddenValue) ' Check to see if the script is already registered. If (Not cs.IsClientScriptBlockRegistered(cstype, csname)) Then Dim cstext As StringBuilder = New StringBuilder() cstext.Append("<script type=text/javascript> function DoClick() {") cstext.Append("Form1.Message.value='Sum = ' + ") cstext.Append("(parseInt(" + arrName + "[0])+") cstext.Append("parseInt(" + arrName + "[1])+") cstext.Append("parseInt(" + Form1.Name + "." + hiddenName + ".value));} </") cstext.Append("script>") cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), False) End If End Sub </script> <html> <head> <title>ClientScriptManager Example</title> </head> <body> <form id="Form1" runat="server"> <input type="text" id="Message" /> <input type="button" onclick="DoClick()" value="Run Script"> </form> </body> </html>
<%@ Page Language="C#"%> <script runat="server"> public void Page_Load(Object sender, EventArgs e) { // Define the array name and values. String arrName = "MyArray"; String arrValue = "\"1\", \"2\", \"text\""; // Define the hidden field name and initial value. String hiddenName = "MyHiddenField"; String hiddenValue = "3"; // Define script name and type. String csname = "ConcatScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Register the array with the Page class. cs.RegisterArrayDeclaration(arrName, arrValue); // Register the hidden field with the Page class. cs.RegisterHiddenField(hiddenName, hiddenValue); // Check to see if the script is already registered. if (!cs.IsClientScriptBlockRegistered(cstype, csname)) { StringBuilder cstext = new StringBuilder(); cstext.Append("<script type=text/javascript> function DoClick() {"); cstext.Append("Form1.Message.value='Sum = ' + "); cstext.Append("(parseInt(" + arrName + "[0])+"); cstext.Append("parseInt(" + arrName + "[1])+"); cstext.Append("parseInt(" + Form1.Name + "." + hiddenName + ".value));} </"); cstext.Append("script>"); cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false); } } </script> <html> <head> <title>ClientScriptManager Example</title> </head> <body> <form id="Form1" runat="server"> <input type="text" id="Message" /> <input type="button" onclick="DoClick()" value="Run Script"> </form> </body> </html>
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ClientScriptManager.RegisterHiddenField メソッドのページへのリンク