identificar evento de tipo Postback



   AUTOR PREGUNTA

Publicado 02 abril 2014 - 17:57

¿En ASP.NET cómo puedo identificar el control del evento de tipo Postback en la carga del documento?


¿Tienes la misma pregunta? Yo también

 

Publicado 03 abril 2014 - 03:00

Con el siguiente código puedes obtener el control que causo el Postback:

public static Control GetPostBackControl(Page page)
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
    control = page.FindControl(ctrlname);
}
else
{
    foreach (string ctl in page.Request.Form)
    {
	    Control c = page.FindControl(ctl);
	    if (c is System.Web.UI.WebControls.Button)
	    {
		    control = c;
		    break;
	    }
    }
}
return control;
}

   AUTOR PREGUNTA

Publicado 03 abril 2014 - 03:49

Gracias Joel, ya pude identificar el control