?
Solved

ASP: onclick button handler

Posted on 2003-02-21
3
Medium Priority
?
1,443 Views
Last Modified: 2012-05-07
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!

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

Thanks


0
Comment
Question by:odisu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:Sashi Rachabattula
ID: 7992662
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  
0
 

Accepted Solution

by:
bradleymr2 earned 300 total points
ID: 7994213
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.

Ryan

<%
      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>")
            Response.Write("</TABLE>")
      end sub
%>
<script language="JavaScript">
      function ShowTable()
      {
            document.all("tblRecords").style.visibility = "visible";
            return true;
      }
</script>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
            <P>
                  <INPUT type=button onClick="return ShowTable();" value="Show Table">
            </P>
            <%
                  RecToTable
            %>
</BODY>
</HTML>
0
 
LVL 4

Expert Comment

by:Wakie
ID: 7997915
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question