In these articles, here I am placing a Method for finding the event generator or you can say Page postback responsible Control in C#.
for example, if we want to know which control causes the Post back the page. you simply use this code.
Control cause = GetPostBackControl(Page);
public static Control GetPostBackControl(Page page) { Control postbackControlInstance = null; string postbackControlName = page.Request.Params.Get(“__EVENTTARGET”); if (postbackControlName != null && postbackControlName != string.Empty) { postbackControlInstance = page.FindControl(postbackControlName); } else { // handle the Button control postbacks for (int i = 0; i < page.Request.Form.Keys.Count; i++) { postbackControlInstance = page.FindControl(page.Request.Form.Keys[i]); if (postbackControlInstance is System.Web.UI.WebControls.Button) { return postbackControlInstance; } } } // handle the ImageButton postbacks if (postbackControlInstance == null) { for (int i = 0; i < page.Request.Form.Count; i++) { if (page.Request.Form.Keys[i] != null && ((page.Request.Form.Keys[i].EndsWith(“.x”)) || (page.Request.Form.Keys[i].EndsWith(“.y”)))) { postbackControlInstance = page.FindControl(page.Request.Form.Keys[i].Substring(0, page.Request.Form.Keys[i].Length – 2)); return postbackControlInstance; } } } return postbackControlInstance; }
Do you know:-
- The Command Class | C# | TrickCode
- C# DataReader ADO.NET |Trickcode
- What is disconnected data access?
- how to Adding Parameters to Commands
- SQL Basics?
- What is Database Preparations?
- SQL vs NoSQL or MySQL vs MongoDB
- What is data provider in C#?
- What is connection string C#?
- [SQL] SELECT Statement | Example
- how to get return value from stored procedure in sql server
- how to prevent sql injection attacks
- What is Database? What is SQL?
- C#.Net How To: Send email in asp.net using c#
If you like the tutorial, then please share this tutorial with your friends on social media.
Post A Comment:
0 comments: