views:

569

answers:

2

If I do a form post w/ a non asp.net control in webforms, how can I get the id of the control that triggered the event from the sender object?

Currently I'm adding a simple form post to my drop down list w/ jQuery and want a method to capture the specific control on the server side ...

$(document).ready(function()
{
    $("*[id$='ddlEmployers']").change(
        function(objEvent)
        {
            document.forms[0].submit();
        }
    );
});
+1  A: 

From JS call .NET's __doPostBack(eventTarget, eventArgument);

Spikolynn
+1  A: 

ASP.NET postbacks rely on the __EVENTTARGET hidden field whose value is typically the UniqueID of the control which triggered the postback. As I see it you have two options:

  • call the __doPostBack routine and pass the UniqueID of your dropdown (most probably ddlEmployers). On the server side you can use Page.FindControl(Request["__EVENTTARGET"])
  • manually set the __EVENTTARGET hidden field and then submit the form:

    $("input[name=__EVENTTARGET]).val("ddlEmployers"); document.forms[0].submit();

korchev