handling event in server control

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
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 ?
 
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
 
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
 
I agree you, I was just looking for the information !
You gave me the exactly accurate and useful answer !
thansk the tip mate,

Lloyd
 
Back
Top