ASP: onclick button handler

I've been trying to run the following code but keep getting a runtime error. At the click of a button, I want it to display a table that is the result of a query. Please help!

<INPUT TYPE="BUTTON" onClick="(<%Response.Write RecToTable(rsFreq)%>)" VALUE="List Frequent calls">


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sashi RachabattulaSCRUM Master, Technical ManagerCommented:
listen onClick is the event and u can call a function from that

what u can do is make a table as hidden and poppulate with all data and onclick of button make table as visible  
Hello odisu,

I'm going to put a little background information about ASP development in this answer.  I'm pretty sure you already know a lot of this (but maybe someone else looking at this question with the same problem may not understand how developing for the Internet works).

When a user to your application loads the ASP page, the entire page (with consists of server-side scripts, client-side scripts and HTML) is processed by the server and sent to the user's web browser (such as Internet Explorer) as an HTML page.  At that point, the interaction between the web server and the user (client) is complete.  

The onClick event handler for the HTML button is used to execute client-side scripts.  Client-side scripts execute solely on the user's PC and do not interact with the server.  Therefore, if you need to talk to a database, you cannot do that with a client-side script, since it has no connection back to the database server.

Functions such as RecToTable are server-side scripts, meaning that they are executed by the web-server (which can connect to the database server) and their visible results are translated into HTML to be sent to the client PC (the user's browser).

Unfortunately, client-side scripts cannot call server-side scripts.  This is the reason why you are getting your error when trying to call RecToTable from the onClick event.

The differences between client-side and server-side scripts are often difficult to grasp at first for new web developers, especially traditional Window developers.  The good news is that in ASP.NET, web development becomes more like windows development, giving you much more power to handle events.

To solve your specific problem, you can do a couple of things:

1) Call RecToTable as part of the normal ASP script and then from the onClick event handler call a Javascript function that displays the table. (see example below)

2) When the user clicks the onClick button, call a Javascript function that reloads the page and shows the table (useful if the values of the table are populated based on the interactions of the user on that page)

3) Use your button to submit a form and, using the Action parameter of the <FORM> tag, reload the page and show your table.

The example below shows option #1, which from the sound of your message will probably solve your problem.  Please let me know if you need any further information.


      sub RecToTable
            Response.Write("<TABLE width='100%' border=1 id='tblRecords' style='VISIBILITY: hidden'>")
            Response.Write("      <TR>")
            Response.Write("            <TD colspan=2><B>Records table</B></TD>")
            Response.Write("      </TR>")
            Response.Write("      <TR>")
            Response.Write("            <TD width='25%'><B>Record 1:</B></TD>")
            Response.Write("            <TD width='75%'>Record 5 text goes here</TD>")
            Response.Write("      </TR>")
            Response.Write("      <TR>")
            Response.Write("            <TD width='25%'><B>Record 2:</B></TD>")
            Response.Write("            <TD width='75%'>Record 5 text goes here</TD>")
            Response.Write("      </TR>")
            Response.Write("      <TR>")
            Response.Write("            <TD width='25%'><B>Record 3:</B></TD>")
            Response.Write("            <TD width='75%'>Record 5 text goes here</TD>")
            Response.Write("      </TR>")
            Response.Write("      <TR>")
            Response.Write("            <TD width='25%'><B>Record 4:</B></TD>")
            Response.Write("            <TD width='75%'>Record 5 text goes here</TD>")
            Response.Write("      </TR>")
            Response.Write("      <TR>")
            Response.Write("            <TD width='25%'><B>Record 5:</B></TD>")
            Response.Write("            <TD width='75%'>Record 5 text goes here</TD>")
            Response.Write("      </TR>")
      end sub
<script language="JavaScript">
      function ShowTable()
            document.all("tblRecords").style.visibility = "visible";
            return true;
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
                  <INPUT type=button onClick="return ShowTable();" value="Show Table">

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.