This documentation is archived and is not being maintained.

Page.RegisterRequiresRaiseEvent Method

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

[Visual Basic]
Public Overridable Sub RegisterRequiresRaiseEvent( _
   ByVal control As IPostBackEventHandler _
)
[C#]
public virtual void RegisterRequiresRaiseEvent(
 IPostBackEventHandler control
);
[C++]
public: virtual void RegisterRequiresRaiseEvent(
 IPostBackEventHandler* control
);
[JScript]
public function RegisterRequiresRaiseEvent(
   control : IPostBackEventHandler
);

Parameters

control
The control to register.

Remarks

Only one server control can be registered per Page request.

Example

[Visual Basic, C#] This example uses the RegisterRequiresRaiseEvent method to register a Button Web server control as require a raise event. Once you have registered the first Button, you can cause the second Button declared in the code to post the results of the first button's click event to the page.

[Visual Basic] 
Sub DisplayUserName(Sender As Object, e As EventArgs) 
   Response.Write("Welcome to " + Server.HtmlEncode(userName.Text))
End Sub

       Sub MyRaiseEvent(Sender As Object, e As EventArgs)
   'Raises a post back event for a control.
    Me.RaisePostBackEvent(userButton, "")
       End Sub 

Sub Page_Load(Sender As Object, e As EventArgs)
    
  'Registers a control as one that requires postback handling
  Me.RegisterRequiresRaiseEvent(userButton)
      End Sub

[C#] 
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);
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Page Class | Page Members | System.Web.UI Namespace

Show: