Wednesday, March 21, 2012

Need more info than args.get_postBackElement().id

The gridview has Edit option on each row and pages at the bottom for paging.

For paging, I just refresh the current gridview (UpdatePanel) with content of the next page.

For edit, I need to load the content of a row into a separate UpdatePanel.

The mouseover of edit & paging show the same elements

__doPostBack('ctl00$ContentPlaceHolder1$grdEvents','LoadEdit$0')

__doPostBack('ctl00$ContentPlaceHolder1$grdEvents','Page$0')

I need to be able to access the variable that contains the second parameter LoadEdit$0/Page$0 to distinguish which action and turn on the coressponding indicator.

Hi,

<inputtype="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />function __doPostBack(eventTarget, eventArgument) {if (!theForm.onsubmit || (theForm.onsubmit() != false)) {theForm.__EVENTTARGET.value = eventTarget;theForm.__EVENTARGUMENT.value = eventArgument;theForm.submit();}}

Analysis

The __doPostBack function takes two arguments, eventTarget and eventArgument. The eventTarget contains the ID of the control that causes the postback and the eventArgument contains any additional data associated with the control. Note that the two hidden fields, "__EVENTTARGET" and "__EVENTARGUMENT," are automatically declared. The value of the eventTarget and eventArgument are stored in the hidden fields. The two hidden variables can be accessed from the code behind using the forms/params collection.

Using the hidden variables you can also find the ID of the control which causes the postback. All you need to do is to retrieve the value of the __EVENTTARGET from the form parameter collection. Take a look at the code below.

Listing 2 – Getting the _EVENTTARGET hidden field

protected void Page_Load(object sender, EventArgs e){  string controlName = Request.Params.Get("__EVENTTARGET");}
The same to eventArgument!
Best Regards,

No comments:

Post a Comment