__EVENTTARGET is null or not an object

N

Nuno

Hi

I create a new .aspx page only with a button and a span (as you can
see)...simple

When I try to click the button returns JS error (__EVENTTARGET is null
or not an object). I research about it and I found some interesting
conclusions,
some people said that this bug was fixed with the SP1 of .NET1.1
others suggests a work around technique.

on a first aproach I installed SP1 but the error persists then I try
to follow a work around technique, adding a directive to the page
(Page.RegisterHiddenField( "__EVENTTARGET", myButtonName);)
to initialize the EVENTTARGET variable but still not working.

What should I do in order to put a simple event running?



<!-- File: Example6.aspx -->
<%@ Page Language="C#" %>

<script runat="server">

protected void OnClickMyButton(object src, EventArgs e)
{
_message.InnerText = "You clicked the button!";
}

</script>
<html>
<body
<form runat="server">
<h2>ASP.NET event page</h2>
<p>
<input type="button" value="Click me!" id="mybutton" name="mybutton"
OnServerClick="OnClickMyButton" runat="server"/>

</p>
<span name="_message" id="_message" runat="server"/>

</form>
</body>
</html>
 
B

bruce barker

__EVENTTARGET and __DoPostback are only rendered if an autopostback control
(one that requires javascritp to post back) is render by the page. if
asp:buttons or asp:imagebuttons are the only control rendered that submit,
the javascript postback client code is not generated (as it not needed).

-- bruce (sqlwork.com)


| Hi
|
| I create a new .aspx page only with a button and a span (as you can
| see)...simple
|
| When I try to click the button returns JS error (__EVENTTARGET is null
| or not an object). I research about it and I found some interesting
| conclusions,
| some people said that this bug was fixed with the SP1 of .NET1.1
| others suggests a work around technique.
|
| on a first aproach I installed SP1 but the error persists then I try
| to follow a work around technique, adding a directive to the page
| (Page.RegisterHiddenField( "__EVENTTARGET", myButtonName);)
| to initialize the EVENTTARGET variable but still not working.
|
| What should I do in order to put a simple event running?
|
|
|
| <!-- File: Example6.aspx -->
| <%@ Page Language="C#" %>
|
| <script runat="server">
|
| protected void OnClickMyButton(object src, EventArgs e)
| {
| _message.InnerText = "You clicked the button!";
| }
|
| </script>
| <html>
| <body
| <form runat="server">
| <h2>ASP.NET event page</h2>
| <p>
| <input type="button" value="Click me!" id="mybutton" name="mybutton"
| OnServerClick="OnClickMyButton" runat="server"/>
|
| </p>
| <span name="_message" id="_message" runat="server"/>
|
| </form>
| </body>
| </html>
 
G

Guest

My personal preference is to create a CodeBehind file and explicitly wire the
event delegate to my event handler. I find it easier to maintain than the
declarative method. But, this is not the problem.

The problem is in your code. Actually multiple problems:

1. No close to the <body> tag - this is the problem that fires the error

yours
<body

correct

<body>

2. No name or id for the form tag. Not a major deal with this single form
approach


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top