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.
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>
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?
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:
Private Sub Page_Load
Dim myTable As New System.Web.UI.WebControls.Table
if (someVariable) then myTable.Rows.Add(new TableRow)
End Sub
If you need further help look into the TableRow and TableCell classes (available via F1 from your msdn help)
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.