views:

147

answers:

3

ASP.NET has a number of nice features regarding making data input pages:

  • Adding input controls is easy (<asp:...).
  • The system automatically generates member variable for the controls.
  • Post-backs automatically populate the members variable with the returned values.

and some not so nice bits

  • post-backs seem to be tied to JavaScript for even the simplest of cases. For instance, with statically defined pages, using only basic controls, that are known at compile time.

My questions:

  • Is is possible to get the first list without the second?
  • What features does that JavaScript give the user?
  • What does that JavaScript actually do?
  • What is the technical reasons that it's used even in trivial cases?


As it happens my assumption were in error: See here

+1  A: 

It really depends on the types of controls you are trying to use here -- the only ones that implement javascript are those that can't natively cause a postback (ie, an input/submit button are the only two that can). If you are using a LinkButton, ImageButton, or anything that you set "AutoPostBack = true" on will turn javascript on in order to cause a postback.

Other controls can also potentially use javascript if they are more advanced such as the Calendar. The technical reason for using javascript here is to provide automated postback when the controls require more advanced server interaction -- think about it, a link is meant to only ever be a link and if we're trying to make it operate as a button we have to force it to do just that through javascript interaction.

So that being said, yes you can definitely use ASP.NET without it having javascript you just have to avoid the controls that implement it by including functionality you couldn't possibly have without it. You can just as easily add HTML controls and add the runat="server" attribute and gain member variables to the control from code-behind.

Fooberichu
+1  A: 

Here's what came to my mind:

What features does that JavaScript give the user?

Client side validation.

What does that JavaScript actually do?

For exmaple, it ensures that the correct (server-side) event handlers are called, by setting the __EVENTTARGET hidden field.

Is is possible to get the first list without the second?

You can use normal HTML controls instead of the ASP.NET controls. Then on the server-side, you can read the control's values from the Form collection.

M4N
+1  A: 

I assume you mean the javascript associated with an <asp:Button /> control, right?

In addition to the reasons mentioned by Fooberichu, the javascript can also help with ASP.NETs client side validation framework.

But I think it's primary use is to alert the framework what events it should fire on the postback in the page behind.

So if you had two buttons on the form, SaveButton and DeleteButton, the javascript helps the framework know whether it should execute the SaveButton_Click event or DeleteButton_Click event.

Hope this helps.

thinkzig