This documentation is archived and is not being maintained.

Page.RegisterRequiresRaiseEvent Method

Registers an ASP.NET server control as one requiring an event to be raised when the control is processed on the Page object.

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

public virtual void RegisterRequiresRaiseEvent (
	IPostBackEventHandler control
)
public void RegisterRequiresRaiseEvent (
	IPostBackEventHandler control
)
public function RegisterRequiresRaiseEvent (
	control : IPostBackEventHandler
)
Not applicable.

Parameters

control

The control to register.

Only one server control can be registered per page request. The RegisterRequiresRaiseEvent must be used when the control does not include its control ID in the form post data. Also, the control that is registered must implement the IPostBackEventHandler interface.

The following code example uses the RegisterRequiresRaiseEvent method to register a Button Web server control as requiring an event to be raised. After you have registered the first Button control, you can cause the second Button control declared in the code to post the results of the first button's click event to the page.

void DisplayUserName(Object sender, EventArgs ea) 
{
   Response.Write("Welcome to " + Server.HtmlEncode(userName.Text));
}
void RaiseEvent(Object sender, EventArgs ea)
{
   // Raise a post back event for a control.
   this.RaisePostBackEvent(userButton, "");
}
void Page_Load(Object sender, EventArgs ea)
{
   // Register a control as one that requires postback handling.
   this.RegisterRequiresRaiseEvent(userButton);
}

void DisplayUserName(Object sender, EventArgs ea) 
{
    get_Response().Write("Welcome to " 
        + get_Server().HtmlEncode(userName.get_Text()));
} //DisplayUserName
      
void RaiseEvent(Object sender, EventArgs ea)
{
    // Raise a post back event for a control.
    this.RaisePostBackEvent(userButton, "");
} //RaiseEvent
      
void Page_Load(Object sender, EventArgs ea)
{
    // Register a control as one that requires postback handling.
    this.RegisterRequiresRaiseEvent(userButton);
} //Page_Load    

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: