1/22/2011

How to find post back element id in asynchronous postback ( UpdatePanel ) ? ASP.NET

A day before I was playing with some functionality where I had to get the id of the element which caused the postback. If its a normal postback done with some control. We can retrieve the postback element with the code below.

string controlID = Page.Request.Params["__EVENTTARGET"];

If we use a UpdatePanel on the page, and if its a asynchronous postback with some control inside the Content template of Update panel, you will observe that EVENTTARGET parameter will be blank. So How to get the postback element id in asynchronous postback caused by Updatepanel in ASP.NET ?

Please use the function below to get the Async postback element id.

///
/// This function retrieves the ID of the control that caused the asynchronous postback.
///

///
public string GetAsyncPostBackControlID()
{
string smUniqueId = ScriptManager.GetCurrent(Page).UniqueID;
string smFieldValue = Request.Form[smUniqueId];

if (!String.IsNullOrEmpty(smFieldValue) && smFieldValue.Contains('|'))
{
return smFieldValue.Split('|')[1];
}

return String.Empty;
}


Hope it helps.

Love ASP.NET tips ? For more Subscribe here or click here to get updates via email

6 comments:

thanks for the information, this is one of the most wanted information as freelancer, you know is not easy to be someone without education, but with all the will to work.

I will try some loops with this. The postback can be at times a risk when hacking pertains to retriever several keyput ids.

Trên thế giới có nhiều loại đông trùng hạ thảo, có loại đông trùng hạ thảo rất quý như đông trùng hạ thảo tây tạng của Việt Nam ở nước chúng ta. Đông trùng hạ thảo là loại có dưỡng chất tốt nhất.
cửa hàng đông trùng hạ thảo hàn quốc quận 4
cửa hàng đông trùng hạ thảo hàn quốc quận 5
cửa hàng đông trùng hạ thảo hàn quốc quận 6

Generic drugs is to give moderate answers for different wellbeing issues easily. Generic meds estimating is so reasonable which can be bought by anybody. This is propelled by keeping this aim mind.
Thanks and Regards
Cheap Viagra Online

Online business procedures are the characterizing parameters for overall organizations. Web based business then again is additionally appropriate inside your homes. We as a whole want to do shopping appropriate on our cell phones while in a hurry.
Thanks
India SEO Company

Sâm tươi hàn quốc: Những điều cấm kị khi sử dụng nhân sâm
Không dùng quá nhiều nhân sâm cùng một lúc:  nhiều người cho rằng nhân sâm là thuốc bổ nên dùng càng nhiều càng tốt. Có nhiều đã sử dụng nhân sâm hãm nước uống quanh năm hoặc ngậm sâm thường xuyên gây ra những hậu quả như mẩn ngứa, phù nề, tiêu  chảy và tăng huyết áp,… việc làm dụng nhân sâm có thể đưa đến nhiều hậu quả nghiêm trọng, nguy hiểm đến tính mạng.
Nguồn: ** https://samyennhatminh.com/nhan-sam-tuoi-han-quoc

Post a Comment