VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
ASP.Net Web Site Posted by RicardoFurtado on 18 Oct 2005 at 3:29 AM
I'm using visual Basic .Net to make a web site and i'm having problems on managing the object contained in the web pages. For example, i have an image who's ID="Img0", when i try to run a script that refers to Img0, like the following:
Img0.src="BoxForn.bmp"
this doesnt work, and an error is shown stating that Img0 is not defined. Now, i was able to overcome this problem by doing the following:
document.images.item("Teste1").src="BoxForn.bmp"
And that, indeed worked for the images i have in the page but for instance, the textbox "txtUser", and other controls, besides the images, don't work, and the error is allways the same "ControlXXX is not defined"
I programmed in html and javascript and i used to do the following when refering to controls in the page
document.Form1.ControlName.value="Value"
But this doen't work either.
There is few documentation on this part of visual basic .net and i need to know this in order to continue the web site, can you please help? following is one of the pages i'm working on, it may help

my thanks in advanced

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--
var Counter=0;
var Utilizador=0;
var Img0Val=0;

function Img0_onclick() {
if(Img0Val==0)
{
document.images.item("Teste1").src="BoxForn.bmp"
Img0Val=1;
}
else
{
document.images.item("Teste1").src="Bar3d.bmp"
Img0Val=0;
}
if(Utilizador==0)
{
Utilizador=1;
}
else
{
Utilizador=0;
}
Counter++;
}

function Img1_onclick() {
alert(document.images.item("Teste2").src="Bar3d.bmp")
if(document.images.item("Teste2").src=="Bar3d.bmp")
{
document.images.item("Teste2").src="BoxForn.bmp"
}
else
{
document.images.item("Teste2").src="Bar3d.bmp"
}
Counter++;
if(Utilizador==0)
{
Utilizador=1;
}
else
{
Utilizador=0;
}
Counter++;
---------> txtUser.value=Utilizador; <---------------------
}

function Img2_onclick() {
alert(document.images.item("Teste3").src="Bar3d.bmp")
if(document.images.item("Teste3").src="Bar3d.bmp")
{
document.images.item("Teste3").src="BoxForn.bmp"
}
else
{
document.images.item("Teste3").src="Bar3d.bmp"
}
Counter++;
txtUtilizador.value="Teste";
}

// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;</div>
<table style="width: 634px; height: 244px">
<tr>
<td>
<img ID="Img0" name="teste1" src="Bar3d.bmp" language="javascript" onclick="return Img0_onclick()" /></td>
<td>
<img id="Img1" name="teste2" src="Bar3d.bmp" language="javascript" onclick="return Img1_onclick()" /></td>
<td>
<img id="Img2" name="teste3" src="Bar3d.bmp" language="javascript" onclick="return Img2_onclick()" /></td>
</tr>
<tr>
<td>
<img id="Img3" name="teste4" src="Bar3d.bmp" /></td>
<td>
<img id="Img4" name="teste5" src="Bar3d.bmp" /></td>
<td>
<img id="Img5" name="teste6" src="Bar3d.bmp" /></td>
</tr>
<tr>
<td>
<img id="Img6" name="teste7" src="Bar3d.bmp" /></td>
<td>
<img id="Img7" name="teste8" src="Bar3d.bmp" /></td>
<td>
<img id="Img8" name="teste9" src="Bar3d.bmp" /></td>
</tr>
</table>
<br />
<input id="txttxtUser" name="MyText" type="text" accesskey="User" />
</form>
</body>
</html>

Report
Re: ASP.Net Web Site Posted by iwilld0it on 18 Oct 2005 at 5:57 AM
Try this form of control access ...

document.forms[0].ControlName.value="Value" 


This should work because there is ONLY one form in a typical ASP.NET page

BTW: The control name is not Img0, you named it teste1.

<img ID="Img0" name="teste1" src="Bar3d.bmp" language="javascript" onclick="return Img0_onclick()" />


If you want to reference a tag by its ID, you can do this:

document.getElementById('Img0');


In this way, you do not have to reference the Form object neither. Most modern browsers will support this syntax.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.