Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

ASP.Net Web Site

RicardoFurtadoRicardoFurtado Posts: 205Member
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">



Untitled Page

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";
}

// -->





 

















image

image

image

image

image

image

image

image

image







Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    Try this form of control access ...

    [code]
    document.[b]forms[0][/b].ControlName.value="Value"
    [/code]

    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.

    [code]
    image
    [/code]

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

    [code]
    document.getElementById('Img0');
    [/code]

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


Sign In or Register to comment.