Javascript in a .net page

  • Thread starter Thread starter Poppy
  • Start date Start date
P

Poppy

I have a .net text field and a .net button on a form.

When the user leaves the text field server side VB.net code fires to check
if anything has been entered and if it has, enables the button.

The problem with this is that it has to do the round trip to the server.

How would I use javascript to do this in a .net page ?
Can I control a .net textbox with javascript ?

TIA
 
yes, by all means you can use javascript to control the elements in your
page. to disable the asp:button add the disabled attribute and set it to
true

<asp:Button id="Button1" disabled=true style="Z-INDEX: 102; LEFT: 176px;
POSITION: absolute; TOP: 232px" runat="server"
Text="Button"></asp:Button>

now you add events to the textbox. I used a combination of keyup and keydown

<asp:TextBox id="TextBox1" onKeyUp="enablebutton();"
onKeyDown="enablebutton();" style="Z-INDEX: 101; LEFT: 176px; POSITION:
absolute; TOP: 184px"
runat="server"></asp:TextBox>

then the javascript

<script language=javascript>
<!--
function enablebutton()
{

if(Form1.TextBox1.value != "")
{
Form1.Button1.disabled = false;
}
else
{
Form1.Button1.disabled = true;
}
}
//-->
</script>

HTH

Jose
 
Thankyou

Jose L Rodriguez said:
yes, by all means you can use javascript to control the elements in your
page. to disable the asp:button add the disabled attribute and set it to
true

<asp:Button id="Button1" disabled=true style="Z-INDEX: 102; LEFT: 176px;
POSITION: absolute; TOP: 232px" runat="server"
Text="Button"></asp:Button>

now you add events to the textbox. I used a combination of keyup and keydown

<asp:TextBox id="TextBox1" onKeyUp="enablebutton();"
onKeyDown="enablebutton();" style="Z-INDEX: 101; LEFT: 176px; POSITION:
absolute; TOP: 184px"
runat="server"></asp:TextBox>

then the javascript

<script language=javascript>
<!--
function enablebutton()
{

if(Form1.TextBox1.value != "")
{
Form1.Button1.disabled = false;
}
else
{
Form1.Button1.disabled = true;
}
}
//-->
</script>

HTH

Jose
 
Back
Top