tags:

views:

290

answers:

1

I am trying to fire a form submit via jQuery and have a particular server side event fire.

Client Side Code:

$("input[name=__EVENTARGUMENT]").val("SomeArg");
form = $("body form");
form.submit();

Server Side Code:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (Request["__EVENTARGUMENT"] == "SomeArg")
            {
                //do some stuff
            }
        }
    }

The problem is, the "__EVENTARGUMENT" hidden input does not exist. I discovered that if I add an ASP.net server control dropdownlist with autopostback = true, the EVENTARGUMENT hidden input is created. Is there a cleaner way to have ASP.net create these hidden inputs, and allow me to get their values server side without adding controls I do not actually need on the page?

+1  A: 

Add asp.net HiddenField control to the page

But you will have a problem which is to get this control id, which as.net generates automatically, you can solve this using the ClientID property for the hidden field like this article mentions

Amr ElGarhy
I added a 'test' HiddenField control to the page. The EVENTARGUMENT hidden field was not auto-generated. I'm wary about creating one with that name since that javascript/page load code is actually on a user control. The user control may be placed on pages that have an autogenerated EVENTARGUMENT hidden field or pages that do not have that control autogenerated.
KClough
why you need this special EVENTARGUMENT ?
Amr ElGarhy
AH! Did not realize that all named input fields were accessible through the Request object. THANKS!
KClough