handling event in server control

L

Lloyd Dupont

I am developing a special control, in fact it's a <td> tag
however on click I need to submit somedata.
so I write

protected void Render(HtmlTextWriter htw)
{
// ......
htw.Write("<td name='{0}' onclick='javascript:submit()'", UniqueID);
// ..
}
and implement IPostBackEventHandler.
however the method RaisePostBackEvent is never called (although the page is
reload), any ideas ?
 
N

Natty Gur

Yep

The doPostback should contain the ID of the control as the first
parameter. ASP.NET uses it to know which control to call. The second
parameter usually used if more than one event exists.

oSTR.Append(" onchange=\"__doPostBack('"+ this.ID +"','change')\"
language=\"javascript\" \n");

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
W

William F. Robertson, Jr.

1. There is no value posted back for a td tag.
2. Rather than just straight submitting the form, you might want to look
into GetPostBackClientEvent method.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwebuipageclassgetpostbackclienteventtopic.asp

protected override void Render( HtmlTextWriter writer )
{
writer.AddAttribute( HtmlTextWriterAttribute.Name, UniqueID );
writer.AddAttribute( HtmlTextWriterAttribute.OnClick,
Page.GetClientPostBackEvent( this, "event args passed to your
RaisePostBackEvent" );
writer.RenderBeginTag( HtmlTextWriterTag.Td );
writer.RenderEndTag();
}

You really should use the "helper" function provided by the page to handle
the postback. By just calling submit, the form is just submitted, it
doesn't know what button ( any other control) triggered the post back.

HTH,

bill
 
L

Lloyd Dupont

I agree you, I was just looking for the information !
You gave me the exactly accurate and useful answer !
thansk the tip mate,

Lloyd
 

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,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top