How to trap postback events on client?

  • Thread starter Thread starter Peter Rilling
  • Start date Start date
P

Peter Rilling

My form has many controls that postback to the server, some are buttons,
some are listboxes. I tried to use the "onsubmit" event to take action just
before the form was posted but then realized that this only happens when a
button is clicked, not when the submit method is called which is how
listboxes are invoked. I basically have some hidden fields that I want to
populate before the form is submitted, regardless of whether a button or
listbox caused the action. How might I do this?
 
Peter

Add an event to the button to trigger on the client side. Alternatively,
when you put a button element, do not mark it as runat=server
 
I need the controls to run at the server. I also have more then just
buttons, such as listboxes that need to be trapped during a postback.
 
Here is another trick, very safe & works well
Also as we are not tampering with the controls, it works harmoniouls

Trick involves disable autopostback & then from client manually posting the for
say you have a combobox, which when clicked, should validate the form, if evrthing is ok, submit the for
else don't submit the for

Dim sSTr As New StringBuilde
sSTr.Append("if (ValidateForm()==false)" & vbCrLf
sSTr.Append(" {return false }" & vbCrLf
sSTr.Append(" else {__doPostBack('CmbCenterCode','')}" & vbCrLf

CmbCenterCode.Attributes.Add("onchange", sSTr.ToString

you will have to write this for every control, Remember to disable autopostback to fals

would appreciate comments, whether it helped or no
 
Back
Top