IPostBackEventHandler not passing event argument

Discussion in 'ASP .Net' started by Mike, Jul 22, 2005.

  1. Mike

    Mike Guest

    I have done this many times but for some reason it's not working, the raise
    postback event fires but the eventArgument passed to it is empty. This is a
    simple custom control that implements
    IPostBackEventHandler

    and I get the href for the a tag using

    string href = this.Page.GetPostBackClientHyperlink(this,
    tab.TabID.ToString());

    In the trace for the postback the argumts is listed but it never arrives at



    public void RaisePostBackEvent(string eventArgument)

    {

    this.Context.Trace.Write("SelectedID=" + eventArgument);

    this.SelectedID = Convert.ToInt32(eventArgument);

    }



    This has got to be another one of the many wier asp.net behaviors, any
    ideas...Thanks...
     
    Mike, Jul 22, 2005
    #1
    1. Advertisements

  2. Did you assign the UniqueID to the name attribute of the custom Control?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    The sun never sets on
    the Kingdom of Heaven
     
    Kevin Spencer, Jul 22, 2005
    #2
    1. Advertisements

  3. Mike

    Mike Guest

    Yes the unique id is set and RaisePostBackEvent is fired but eventArgument
    passed to it is empty.
     
    Mike, Jul 22, 2005
    #3
  4. Mike

    Mike Guest

    See Event Below:

    public void RaisePostBackEvent(string eventArgument)
    {
    // this writes the correct value
    this.Context.Trace.Write("eventArgument=" +
    this.Page.Request["__EVENTARGUMENT"]);

    // this does NOT write the correct value, it is empty
    this.Context.Trace.Write("eventArgument=" + eventArgument);

    this.SelectedID = Convert.ToInt32(eventArgument);
    }
     
    Mike, Jul 22, 2005
    #4
  5. What does your LoadPostData method look like?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    The sun never sets on
    the Kingdom of Heaven

     
    Kevin Spencer, Jul 22, 2005
    #5
  6. Mike

    Mike Guest

    I did read that you may need to implement IPostBackDataHandler, would sure
    like to know why?

    I did try it with the same results and the code is below:

    public bool LoadPostData(String postDataKey, NameValueCollection values)
    {
    return false;
    }

    public void RaisePostDataChangedEvent()
    {

    }



     
    Mike, Jul 22, 2005
    #6
  7. Hi Mike,

    The LoadPostData method is the one where you get the value from the
    drop-down list box. You would then loop through your data source to figure
    out the selected index.

    I have an article/tutorial that does just that (using VB.Net as the
    language). See:

    http://www.takempis.com/aspnet_anatomy3.asp

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    The sun never sets on
    the Kingdom of Heaven

     
    Kevin Spencer, Jul 22, 2005
    #7
  8. Mike

    Mike Guest

    Kevin,

    This is a control that writes the html for a couple of links, no child
    controls. I am simply using an anchor tag with
    Page.GetPostBackClientHyperlink(this, linkID) as the href attribute when
    rendering the control. linkID is just an internal ID so that the control can
    tell wich link was clicked: 0,1,2,3 and so on...

    The problem is that when RaisePostBackEvent is called the eventArgumet
    parameter does not contain my internal ID that I pass with each link as
    shown below. __EVENTARGUMENT is there just as it should be but dotnet never
    hands it to my implementation of the RaisePostBackEvent. I can get it to
    work if I just grab __EVENTARGUMENT from the Request object but that seems
    like a rediculus hack.

    public void RaisePostBackEvent(string eventArgument)
    {
    // this writes the correct value
    this.Context.Trace.Write("eventArgument=" +
    this.Page.Request["__EVENTARGUMENT"]);
    // this does NOT write the correct value, it is empty
    this.Context.Trace.Write("eventArgument=" + eventArgument);
    }

    Thanks,

    Mike


     
    Mike, Jul 22, 2005
    #8
  9. Mike

    Mike Guest

    PROBLEM SOLVED!!!!!

    I did a project wide search for RegisterRequiresRaiseEvent and found
    Page.RegisterRequiresRaiseEvent(this) was being called in another control on
    the page. This completely breaks all other events on the page.

    Spent two days trying to figure this out so maybe this helps someone else.

    I know exactly why this caused a problem but this is just one more example
    of one of those wierd things that dotnet does that drives me crazy.

    Mike
     
    Mike, Jul 23, 2005
    #9
  10. Glad you got it solved Mike, as I was away over the weekend!

    --

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    The sun never sets on
    the Kingdom of Heaven
     
    Kevin Spencer, Jul 25, 2005
    #10
  11. Mike

    Guest Guest

     
    Guest, Sep 22, 2005
    #11
  12. Mike

    Guest Guest

    I wonder if the Page.RegisterRequiresRaiseEvent and Page.RequiresPostBack are
    asp.net bugs,for they are somewhat "ugly" and difficult to use.At the same
    time, I wonder if there is other alternatives I can choose.I've read the book
    "Developing Microsoft ASP.NET Server Controls and Components" by Nikhil
    Kothari, and here is some codes in LoadPostData method in code list 9-11:

    bool buttonClicked = (buttonValue != null) && (buttonValue.Length != 0);
    if (buttonClicked) Page.RegisterRequiresRaiseEvent(this);

    Reading these codes,I feel I go back to the asp times again. these are
    somewhat ugly.
     
    Guest, Sep 22, 2005
    #12
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.