document.webform1 gives null

G

Guest

Hello,
I am using java script to post data back to the server when a button
is clicked.
In my web form, when a button is clicked, a javascript executes which
submits data back to the server by following statment
document.WebForm1.submit( );

But when i click on the button i am getting document.webform1 is null or not
an object.

The code is as follows

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="N.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="vs_showGrid" content="False">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script id="clientEventHandlersJS" language="javascript">
<!--

function btn1_onclick() {
document.WebForm1.submit( );
}
//-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" name="WebForm1" method="post" runat="server">
<input type="hidden" name="operation"> <INPUT id="btn1" style="Z-INDEX:
101; LEFT: 112px; POSITION: absolute; TOP: 112px" ype="button"
value="Button1" language="javascript" onclick="return btn1_onclick()">
</form>
</body>
</HTML>

Can any one help me please?

Thanks,
Sushi
 
D

DalePres

Other than a typo that your input element has "ype=button" instead of
"type=button", your code works for me.

DalePres
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

It should work fine, what browser are you using?
what if you use document.forms[0] ?

btw, there is no need to do a "return ... " in the onclick , saying:
onclick=" FUNCTION();"
is enough.

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top