Results 1 to 5 of 5

Thread: asp.net and javascript questions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    asp.net and javascript questions

    I am remaking this webpage and I have come across asp code.

    In it the programmer used a lot of javascript headed by this symbol "<@".
    Can anyone tell me what that means.

    Also can anyone tell me the way to call javascript functions from within html.

    The javascript code written will populate this table in the page using javascript calls to create each item in the rows.

    Any help would be appreciated.

    Thanks again.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: asp.net and javascript questions

    In the browser arena, you have 3 choices:

    1) Inline script
    2) Link to an external script file
    3) server-side generated script (like option 1, but its inclusion is determined by the server processing logic - so you can include the javascript based on some variable, or exclude it).

    Calling javascript from within html is as simple as assigning a javascript function to handle an event raised by the browser and passed to the javascript runtime.

    User clicks a textbox

    Browser raises a click event

    Click event gets passed down to the javascript runtime

    Javascript runtime raises a click event

    If a javascript event handler is assigned to the control that raised the event, and the event signature matches, it runs the javascript code assigned for that event - which in most cases calls some javascript function you have previously defined.
    Code:
    <html>
    <body>
    <form>
    <script language="javascript" type="text/javascript">
    function myjavascriptfunction()
    {
     alert("hi");
    }
    </script>
    <asp:textbox id="someinput" runat="server" onClick="myjavascriptfunction()" />
    </form>
    </body>
    </html>

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    Re: asp.net and javascript questions

    But what if I would like to do it at page load? The current version looks like this

    <table>
    <%
    for (x=1;something;something) {
    If (meets some requirement) {
    %>
    <tr>
    <td><% call some javascript function %></td>
    <td><% call some javascript function %></td>
    </tr>
    <%
    }
    }
    <%>

    How would something like that look in asp.net?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: asp.net and javascript questions

    Handle it on the code-behind... and drop the javascript entirely. The previous author probably enlisted the help of javascript to build the table since classic asp was so inept at doing such things. Figure out what the js is supposed to do, and replicate it using server-side programming instead.

    VB Code:
    1. Private Sub Page_Load
    2.  Dim myTable As New System.Web.UI.WebControls.Table
    3.  if (someVariable) then myTable.Rows.Add(new TableRow)
    4. End Sub

    If you need further help look into the TableRow and TableCell classes (available via F1 from your msdn help)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    Re: asp.net and javascript questions

    Thanks, I was thinking of doing that, but I had to do some research into MAPI in order to be able to replicate the code in the code-behind in order to populate the table, but I believe I have figured it out and will be able to do so now.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width