hi, geht es, dass ich auf einer aspx seite diese sachen rausbekomme:
geht das?
danke 🙂
public static Control GetPostbackControl(Page page)
{
try
{
Control control = null;
string ctrlname = page.Request.Params["__EVENTTARGET"];
if (ctrlname != null && ctrlname != String.Empty)
{
control = page.FindControl(ctrlname);
}
// if __EVENTTARGET is null, the control is a button type and we need to
// iterate over the form collection to find it
else
{
string ctrlStr = String.Empty;
Control c = null;
foreach (string ctl in page.Request.Form)
{
// handle ImageButton controls ...
if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
{
ctrlStr = ctl.Substring(0, ctl.Length - 2);
c = page.FindControl(ctrlStr);
}
else
{
c = page.FindControl(ctl);
}
if (c is System.Web.UI.WebControls.Button ||
c is System.Web.UI.WebControls.ImageButton)
{
control = c;
break;
}
}
}
return control;
}
catch(Exception)
{
return null;
}
}
Achtung! - Hinter dir ist ein dreiköpfiger Affe!
Hallo math55
Original von math55
bin noch etwas neu in aspx etc...wie setze ich das ein?
Erstelle eine Klasse im App_Code bzw. einem normalen Verzeichnis, füge diese Methode hinzu, und benutze die Funktion wo du willst.
Evt. noch Namespaces einbauen und importieren.
Gruss Peter
--
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland 2007 - 2011
hi, und wie würde ich das ganze aus einer cs datei machen, wenn ich request und response hab? wohlgemerkt, es ist keine codebehind datei der aspx. es ist eine völlig andre cs datei, die aber eben response und request hat.
grüße und besten dank 🙂
Hallo math55
Ich verstehe deine Frage nicht wirklich, tut mir leid.
In irgend einer Klasse hast du auch Zugriff auf die Server Objekte.
Verwende dazu: HttpContext.Current.<Objekt>.
Du kannst diese statische Methode doch einfach in der Codebehind deiner ASPX Datei aufrufen, und dabei die aktuelle Page Instanz übergeben.
Gruss Peter
--
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland 2007 - 2011