Attributes

 

  The confirm() method is used to display a dialog with the specified message and OK and Cancel buttons.

Attributes refers to a collection of attributes, located under using Systems.Web.UI.HtmlControls, used to obtain a collection of all attribute name and value pairs represented on the server space tag within an ASP.NET page.

 

<form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click"/>
    </div>
    </form>

 

 protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Attributes.Add( " onclick " , " confirm('1') " ); // Add a pair of attributes, name-value pair 
        Button1.Attributes.Remove( " onclick " ); // No effect, because Removing the name of this attribute automatically removes the value 
        Button1.Attributes.Add( " onclick " , " confirm('2') " );
    }

 

 Experiments have shown that changing the name to another name will not work, but I don't know why

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325074143&siteId=291194637