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. General Programming
  3. C#
  4. ASP.NET C# Custom Control with Postback.

ASP.NET C# Custom Control with Postback.

Scheduled Pinned Locked Moved C#
csharpasp-nethelptutorialannouncement
16 Posts 5 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.
  • Richard DeemingR Richard Deeming

    So you just want to expose an event from your custom control?

    public class CusParamTextBox : BaseParam
    {
    public event EventHandler ExposedUpdate;

    protected virtual void OnExposedUpdate(EventArgs e)
    {
    var handler = ExposedUpdate;
    if (handler != null) handler(this, e);
    }

    ...

    private void ParamTxtBox_TextChanged(object sender, EventArgs e)
    {
    ...
    OnExposedUpdate(e);
    }
    }

    ...

    var tmpctrlx = new CusParamTextBox();
    tmpctrlx.ExposedUpdate += Update;

    ...

    protected void Update(object sender, EventArgs e)
    {
    var cuscontrol = (CusParamTextBox)sender;
    DoSomethingOnPage(cuscontrol.name, cuscontrol.value);
    upMain.Update();
    }


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    F Offline
    F Offline
    Forbiddenx
    wrote on last edited by
    #7

    Yes, I want to expose a event that I can hook too. So, I can tell it to fire in the local control... but pretty much do nothing locally... but then hook it to a page event that will do the heavy lifting.

    =)

    Richard DeemingR 1 Reply Last reply
    0
    • F Forbiddenx

      Yes, I want to expose a event that I can hook too. So, I can tell it to fire in the local control... but pretty much do nothing locally... but then hook it to a page event that will do the heavy lifting.

      =)

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #8

      So, pretty much exactly the example I posted then? :)


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      F 2 Replies Last reply
      0
      • F Forbiddenx

        The site let me post twice during the process of writing a single post. There was no confirm, and when I hit a hotkey and my work posted instantly.. Then I clicked back and it let me edit the text I was working on and then when I clicked post again it created a new post and posted again instantly. Ultimately the problem is both user error on mypart and also software error on the forums part. I am new, so I did not realize what just happened.. and the software did not detect that I posted twice from the same exact page...... I quick guid check or confirm could of taken place to prevent me from double posting.. And I could of stopped it if I realized it. So, I apologize for my mistake, but I cant take all the credit!

        =)

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #9

        Thank you, I have posted a note at http://www.codeproject.com/Messages/4636599/Dulicate-posts.aspx[^], so the site administrators can investigate.

        Use the best guess

        1 Reply Last reply
        0
        • F Forbiddenx

          The site let me post twice during the process of writing a single post. There was no confirm, and when I hit a hotkey and my work posted instantly.. Then I clicked back and it let me edit the text I was working on and then when I clicked post again it created a new post and posted again instantly. Ultimately the problem is both user error on mypart and also software error on the forums part. I am new, so I did not realize what just happened.. and the software did not detect that I posted twice from the same exact page...... I quick guid check or confirm could of taken place to prevent me from double posting.. And I could of stopped it if I realized it. So, I apologize for my mistake, but I cant take all the credit!

          =)

          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #10

          Member 4632726 wrote:

          Then I clicked back and it let me edit the text I was working on and

          If you had hit "Post Message" without editing, our system would have rejected the duplicate post. As it stands, you edited the text and hit send so our system thinks you simply posted a new, different message. When you posted the original message you would have seen, just under your message, links to edit or delete your message. We will be making changes that will make it even harder to repost accidentally.

          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

          1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            So, pretty much exactly the example I posted then? :)


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            F Offline
            F Offline
            Forbiddenx
            wrote on last edited by
            #11

            Yes, Thank you so much! That is working like a charm!

            =)

            1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              So, pretty much exactly the example I posted then? :)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              F Offline
              F Offline
              Forbiddenx
              wrote on last edited by
              #12

              Ok, I do have a new problem now.. It seems when I put this code into my update panel... It continues to do a full post back all the time... Any idea how how to solve this any one ? Thanks!

              =)

              Richard DeemingR 1 Reply Last reply
              0
              • F Forbiddenx

                Ok, I do have a new problem now.. It seems when I put this code into my update panel... It continues to do a full post back all the time... Any idea how how to solve this any one ? Thanks!

                =)

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #13

                Have you added an AsyncPostBackTrigger[^] for the control?


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                F 1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  Have you added an AsyncPostBackTrigger[^] for the control?


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  F Offline
                  F Offline
                  Forbiddenx
                  wrote on last edited by
                  #14

                  I did try something like that, but a little different because I am adding the controls dynamically to a existing update panel. I did try but with no luck..

                  CusParamTextBox tmpctrlx = new CusParamTextBox();
                  tmpctrlx.ExposedUpdate += new EventHandler(UpdateText);
                  ScriptManager1.RegisterAsyncPostBackControl(tmpctrlx);
                  CusParamControls.Controls.Add(tmpctrlx);

                  and on the page that contains the dyn control

                  =)

                  Richard DeemingR 1 Reply Last reply
                  0
                  • F Forbiddenx

                    I did try something like that, but a little different because I am adding the controls dynamically to a existing update panel. I did try but with no luck..

                    CusParamTextBox tmpctrlx = new CusParamTextBox();
                    tmpctrlx.ExposedUpdate += new EventHandler(UpdateText);
                    ScriptManager1.RegisterAsyncPostBackControl(tmpctrlx);
                    CusParamControls.Controls.Add(tmpctrlx);

                    and on the page that contains the dyn control

                    =)

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #15

                    Sorry, I'm not overly familiar with the UpdatePanel. You might be better off posting this new issue in its own thread. NB: It would be better to post the question in the ASP.NET forum[^].


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    F 1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      Sorry, I'm not overly familiar with the UpdatePanel. You might be better off posting this new issue in its own thread. NB: It would be better to post the question in the ASP.NET forum[^].


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      F Offline
                      F Offline
                      Forbiddenx
                      wrote on last edited by
                      #16

                      Hi Rich, Its ok, I manged to figure it out.. I wanted to add the solution to the post too so other may do the same. Right after your add your control, and then your event via the init... If you want to put your control inside a update panel and stop a full page post back then you must register your control with the parent page and do it inside the actually control code itself... outside dont seem to work via the main page containing the control.

                      protected override void OnInit(EventArgs e)
                      {
                      base.OnInit(e);

                      ScriptManager script = ScriptManager.GetCurrent(Page);
                      TxtParamValue = new TextBox();
                      TxtParamValue.TextChanged += new EventHandler(TxtParamValue_TextChanged);
                      if (script != null) { script.RegisterAsyncPostBackControl(TxtParamValue);}
                      base.Controls.Add(TxtParamValue);
                      }

                      Thanks, and enjoy all!

                      =)

                      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