HtmlForm.SubmitDisabledControls 屬性

定義

取得或設定布林值 (Boolean),指出是否要強制用戶端上已停用的控制項送出其值,讓控制項在網頁回傳至伺服器時保留其值。

public:
 virtual property bool SubmitDisabledControls { bool get(); void set(bool value); };
public virtual bool SubmitDisabledControls { get; set; }
member this.SubmitDisabledControls : bool with get, set
Public Overridable Property SubmitDisabledControls As Boolean

屬性值

Boolean

如果用戶端上停用的控制項被強制送出其值,則為 true,否則為 false。 預設值是 false

範例

下列程式碼範例示範如何將表單上的 屬性設定 SubmitDisabledControls 為 , true 使用戶端腳本停用的控制項在頁面回傳回伺服器之後維持其值。 在此範例中,如果您將 屬性設定 SubmitDisabledControlsfalse ,然後按一下 [ 回傳] 按鈕,則會遺失 HTML 文字方塊中的文字,而且不再選取 [HTML] 核取方塊。

<%@ page language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
    
    // The first time the page loads, set the values
    // of the HtmlInputText and HtmlInputCheckBox controls.
    if (!IsPostBack)
    {
      InputText1.Value = "Test";
      InputCheckBox1.Checked = true;
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" 
      runat="server">

    <title>HtmlForm SubmitDisabledControls Property Example</title>

</head>

<body>

  <form id="form1" 
        submitdisabledcontrols="true" 
        runat="server">
    
      <h3>HtmlForm SubmitDisabledControls Property Example</h3>
    
      <input id="InputText1" 
             name="InputText1" 
             type="text" 
             runat="server" />
    
      <input id="InputCheckBox1" 
             name="InputCheckBox1" 
             type="Checkbox" 
             runat="server" />
    
      <asp:button id="PostBackButton"
                  text="Post back"
                  runat="server" />

  </form>    
    
</body>

</html>

<script type="text/javascript">

    // Disable the HTML controls on the form.
    document.all('InputText1').disabled = true;
    document.all('InputCheckBox1').disabled = true;

</script>
<%@ page language="VB"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
    ' The first time the page loads, set the values
    ' of the HtmlInputText and HtmlInputCheckBox controls.
    If Not IsPostBack Then
      InputText1.Value = "Test"
      InputCheckBox1.Checked = True
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" 
      runat="server">

    <title>HtmlForm SubmitDisabledControls Property Example</title>

</head>

<body>

  <form id="form1" 
        submitdisabledcontrols="true" 
        runat="server">
    
      <h3>HtmlForm SubmitDisabledControls Property Example</h3>
    
      <input id="InputText1" 
             name="InputText1" 
             type="text" 
             runat="server" />
    
      <input id="InputCheckBox1" 
             name="InputCheckBox1" 
             type="Checkbox" 
             runat="server" />
    
      <asp:button id="PostBackButton"
                  text="Post back"
                  runat="server" />

  </form>    
    
</body>

</html>

<script type="text/javascript">

    // Disable the HTML controls on the form.
    document.all('InputText1').disabled = true;
    document.all('InputCheckBox1').disabled = true;

</script>

備註

SubmitDisabledControls使用 屬性指定是否要在頁面回傳時強制用戶端上停用的控制項提交其值。 這可讓停用的控制項在頁面回傳至伺服器之後保留其值。 SubmitDisabledControls當 屬性設定為 false 時,下次頁面回傳時,將不會提交已停用用戶端腳本之表單上的控制項至伺服器。 因此,停用的控制項所儲存的任何值都將遺失。 若要允許停用的控制項在頁面回傳回伺服器之後保留其值,請將 SubmitDisabledControls 屬性設定為 true

適用於