Avatar of andrew67
andrew67 asked on

asp.net custom form validation using javascript

hi everyone i have the following form that i use to upload files to a web server

<form enctype="multipart/form-data" runat="server">
<tr>
  <td>Select file:</td>
  <td><input id="uplTheFile" type=file runat="server"></td>
</tr>
<tr>
  <td colspan="2">
  <input type=button id="btnUploadTheFile" value="Upload"
                    OnServerClick="btnUploadTheFile_Click" runat="server">
  </td>
</tr>
</form>

this works fine, however i want to call a javascript function when they click the upload button so i can show a hidden layer that say processing.  the problem is i cant get the form to call my javascript i have tried this

<form enctype="multipart/form-data" runat="server" onsubmit="return checkform(this); return false;" >

but it never gets called

can anyone point me in the right direction

thanks


ASP.NETJavaScript

Avatar of undefined
Last Comment
HonorGod

8/22/2022 - Mon
Bob Learned

Did you try attaching to the client-side click?

   btnUploadTheFile.Attributes["onClick", ...

Bob
ASKER
andrew67

sorry can expand a little on what you mean by this

thanks
HonorGod

The "return false" can't be executed...

What value is returned by checkform() ?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
andrew67

nothing at all its as if the javascript isnt even called this is the code generated at run time, as you can see the button calls another function and just submits the form

<form name="_ctl0" method="post" action="form1.aspx?user_id=pf&amp;currentFiles=2,1,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24" id="_ctl0" enctype="multipart/form-data" onsubmit="return checkform(this); return false;">
<input type="hidden" name="user_id" value="pf" />
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDw1NDIxMjQwODM7dDw7bDxpPDA+Oz47bDx0PHA8cDxsPFRleHQ7PjtsPFw8Zm9ybSBtZXRob2Q9InBvc3QiIGFjdGlvbj0id29ya2VyLnBocCIgbmFtZT0idXBsb2FkZWRmaWxlcyJcPlw8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJmcm1bY2FzZV0iIHZhbHVlPSIiIGlkPSJjYXNlIiAvXD5c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__doPostBack(eventTarget, eventArgument) {
            var theform;
            if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
                  theform = document._ctl0;
            }
            else {
                  theform = document.forms["_ctl0"];
            }
            theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
            theform.__EVENTARGUMENT.value = eventArgument;
            theform.submit();
      }
// -->
</script>

<tr>
  <td>Select file:</td>
  <td><input name="uplTheFile" id="uplTheFile" type="file" /></td>

</tr>
<tr>
  <td colspan="2">
  <input language="javascript" onclick="__doPostBack('btnUploadTheFile','')" name="btnUploadTheFile" id="btnUploadTheFile" type="button" value="Upload" />
  </td>
</tr>
</form>
HonorGod

hm.  I wonder if the runat='server' is causing the "local" routine to not be executed...
ASKER
andrew67

is there a way i can add content to the function __doPostBack(

that is auto generated
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
andrew67

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
HonorGod

Good to know.  Thanks for sharing.