Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / September 2006

Tip: Looking for answers? Try searching our database.

post back event in server control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon   Paal - 20 Sep 2006 19:40 GMT
how do I get the button event recognized in the post back from a server control ??

========code=============

  Public Class MyButton
     Inherits System.Web.UI.Page
     Implements IPostBackEventHandler

  Public Response As HttpResponse = HttpContext.Current.Response

     ' Defines the Click event.
     '-----------------------------
     Public Event Click As EventHandler

     ' OnClick dispatches the event to delegates that
     ' are registered with the Click event.
     ' Controls that derive from MyButton can handle the
     ' Click event by overriding OnClick
     ' instead of attaching a delegate. The event data
     ' is passed as an argument to this method.
     '-----------------------------------------------
     Protected Overridable Sub OnClick(e As EventArgs)
        RaiseEvent Click(Me, e)
     End Sub

     ' Method of IPostBackEventHandler that raises change events.
     '-----------------------------------------------------------
     Public Sub RaisePostBackEvent(eventArgument As String)
Implements  PostBackEventHandler.RaisePostBackEvent
        OnClick(EventArgs.Empty)
        System.Web.UI.Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", _
     "function AlertHello() { alert('Hello'); }", True)
     End Sub 'RaisePostBackEvent

     Public Sub New()
        Response.Write("<INPUT TYPE = submit name = " & Me.UniqueID & " Value = 'Click Me' />")
     End Sub

   End Class
Gaurav Vaish (www.EduJiniOnline.com) - 24 Sep 2006 06:54 GMT
> how do I get the button event recognized in the post back from a server
> control ??

Don't use 'Response.Write'.
But use:

override CreateChildControls()
{

   base.CreateChildControls();

   Button btn = new Button;
   btn.Text = ...
   btn.Value = ...
   Controls.Add(btn);

}

Signature

Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.