Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Raise CustomEvent From UserControl

Raise CustomEvent From UserControl

Scheduled Pinned Locked Moved ASP.NET
helpannouncement
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yazali
    wrote on last edited by
    #1

    Hi.. I have a UserControl named MyControl.I have placed a Button on this UserControl.I placed this UserControl on my webForm named Default.aspx.My requirement is to raise CustomEvent when i click the Button. This is the code i tried..... //in MyControl.ascx.cs public event System.EventHandler Hello; //in Button_click event this.Hello(this, new EventArgs()); //in default.aspx.cs protected MyControl MyControl1; //in page_Load this.MyControl.Hello +=new EventHandler(MyControl_Hello); //after Page_load private void MyControl_Hello(object sender, EventArgs e) { Response.Write("welcome"); } ---------------------------------------------------------------------------- i am able to print "welcome" in 1.1 version.Above code is working fine.but in 2.o its not working.i need this in 2.0.plz anyone help me.....................

    X 1 Reply Last reply
    0
    • Y yazali

      Hi.. I have a UserControl named MyControl.I have placed a Button on this UserControl.I placed this UserControl on my webForm named Default.aspx.My requirement is to raise CustomEvent when i click the Button. This is the code i tried..... //in MyControl.ascx.cs public event System.EventHandler Hello; //in Button_click event this.Hello(this, new EventArgs()); //in default.aspx.cs protected MyControl MyControl1; //in page_Load this.MyControl.Hello +=new EventHandler(MyControl_Hello); //after Page_load private void MyControl_Hello(object sender, EventArgs e) { Response.Write("welcome"); } ---------------------------------------------------------------------------- i am able to print "welcome" in 1.1 version.Above code is working fine.but in 2.o its not working.i need this in 2.0.plz anyone help me.....................

      X Offline
      X Offline
      xenonysf
      wrote on last edited by
      #2

      Seems ok. But if you are not using "EventArgs e" you pass null instead of "new EventArgs();". and on the other hand i think it is better to initialize event handlers in OnInit instead of Page_Load.. What do you think guys?

      Y 1 Reply Last reply
      0
      • X xenonysf

        Seems ok. But if you are not using "EventArgs e" you pass null instead of "new EventArgs();". and on the other hand i think it is better to initialize event handlers in OnInit instead of Page_Load.. What do you think guys?

        Y Offline
        Y Offline
        yazali
        wrote on last edited by
        #3

        what you told is exactly correct.bcoz i got error object ref is not set to an instance of an object.but i am not getting how to handle it.i thought u hav a good knowledge on this topic.plz help me...(wats the code i need to write)

        X 1 Reply Last reply
        0
        • Y yazali

          what you told is exactly correct.bcoz i got error object ref is not set to an instance of an object.but i am not getting how to handle it.i thought u hav a good knowledge on this topic.plz help me...(wats the code i need to write)

          X Offline
          X Offline
          xenonysf
          wrote on last edited by
          #4

          //in MyControl.ascx.cs public event System.EventHandler Hello; //in Button_click event ///I suggest: if(this.Hello != null) this.Hello(this, null); //in default.aspx.cs protected MyControl MyControl1; //in page_Load XX ///override OnInit protected override void OnInit(EventArgs e) { base.OnInit(e); this.MyControl.Hello +=new EventHandler(MyControl_Hello); } //after Page_load private void MyControl_Hello(object sender, EventArgs e) { //this is not a good way put a label and assing your value to it Response.Write("welcome"); }

          Y 1 Reply Last reply
          0
          • X xenonysf

            //in MyControl.ascx.cs public event System.EventHandler Hello; //in Button_click event ///I suggest: if(this.Hello != null) this.Hello(this, null); //in default.aspx.cs protected MyControl MyControl1; //in page_Load XX ///override OnInit protected override void OnInit(EventArgs e) { base.OnInit(e); this.MyControl.Hello +=new EventHandler(MyControl_Hello); } //after Page_load private void MyControl_Hello(object sender, EventArgs e) { //this is not a good way put a label and assing your value to it Response.Write("welcome"); }

            Y Offline
            Y Offline
            yazali
            wrote on last edited by
            #5

            hi... still i am getting same error.plzzzz check once again the code u posted.

            X 1 Reply Last reply
            0
            • Y yazali

              hi... still i am getting same error.plzzzz check once again the code u posted.

              X Offline
              X Offline
              xenonysf
              wrote on last edited by
              #6

              man i don't know then your problem is something else, try giving more detail about the error

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups