For people who are older than a kindergartener, a visit to the doctor for advice is in order. There are biofeedback measures and, for some, medication that may help. It just depends on the physiology...
There are many causes of bed wetting/wetting your pants- most children/young adults who do this are completely normal and therefore, problem can be remedied easily. Sometimes though there are other...