IPostBackEventHandler not passing event argument

M

Mike

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...
 
K

Kevin Spencer

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
 
M

Mike

Yes the unique id is set and RaisePostBackEvent is fired but eventArgument
passed to it is empty.
 
M

Mike

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);
}
 
K

Kevin Spencer

What does your LoadPostData method look like?

--
HTH,

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

Mike said:
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);
}


Kevin Spencer said:
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
 
M

Mike

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()
{

}



Kevin Spencer said:
What does your LoadPostData method look like?

--
HTH,

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

Mike said:
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);
}


Kevin Spencer said:
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

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...
 
K

Kevin Spencer

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

Mike said:
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()
{

}



Kevin Spencer said:
What does your LoadPostData method look like?

--
HTH,

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

Mike said:
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);
}


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

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...
 
M

Mike

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


Kevin Spencer said:
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

Mike said:
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()
{

}



Kevin Spencer said:
What does your LoadPostData method look like?

--
HTH,

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

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);
}


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

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...
 
M

Mike

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
 
K

Kevin Spencer

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
 
G

Guest

Kevin Spencer said:
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
 
G

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top