Solved

ASP.NET doPostBack - Error : Expected ';' ?

Posted on 2004-03-21
7
2,041 Views
Last Modified: 2012-05-04
I have a form which is showing the error as Error : Expected ';' at  the javascript autogenerated by ASP.NET
here is the autogenerated code for your info
====================================
<form name="_ctl0:Default" method="post" action="MyForm.aspx" id="_ctl0_Default">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDw1MDcyNzUzNTY7dDw7bDxpPDI" />

<script language="javascript">
<!--
      function __doPostBack(eventTarget, eventArgument) {
            var theform;
            if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
                  theform = document.forms["_ctl0:Default"];
            }
            else {
                  theform = document._ctl0:Default;
            }
            theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
            theform.__EVENTARGUMENT.value = eventArgument;
            theform.submit();
      }
// -->
</script>
==============================

now the error is showing at the : (colon)
             else {
      theform = document._ctl0:Default;


Iam using Visual Studio 2003 with Framework 1.1,
OS : Windows 2003 Server Standard,
and IE 6

Why iam getting this error and how to rectify this.. Any help would get points immediately
0
Comment
Question by:pratap_surisoft
7 Comments
 

Author Comment

by:pratap_surisoft
ID: 10647186
Hi all, I just have 20 points to ask a question and i given the best, but this question worth 500 points i am sure
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10647249
i think that the problem can invoke by the name of the form
can you post the <form> tag

if the id of the form tag is Default it can cause such a problem
if i'm write change the id of the form tag with no usual value

B..G
0
 

Expert Comment

by:Dekkert
ID: 10647261
Hi, try removing all : characters. Also in your form name. Afaik javascript doesn't like colons.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:pratap_surisoft
ID: 10647532
That code was autogenerated by ASP.NET, nothing was done by me..  
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10647569
yes,

but it's base on the
<form id="Default" method="post" runat="server"> which is again autogenerated from the vs in your html code of the .aspx

so you have to change the id from Default to something else because Default is reserved

B..G
0
 

Accepted Solution

by:
Rana_blr earned 20 total points
ID: 10647632
Hi, This is a problem with Framework 1.1,
just add the following code to ur codebehind and it will render the html and your error will go on the fly.
getback to me if it wont goes

using System.IO;
using System.Text;

protected override void Render(HtmlTextWriter writer) {
  StringBuilder stringBuilder = new StringBuilder();
  StringWriter stringWriter = new StringWriter(stringBuilder);
  HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
  base.Render(htmlWriter);
  string html = stringBuilder.ToString();

  int start = html.IndexOf("<form name=\"") + 12;
  int end = html.IndexOf("\"", start);
  string formID = html.Substring(start, end - start);
  string replace = formID.Replace(":", "_");
  html = html.Replace("document." + formID, "document." + replace);
  writer.Write(html);
}

0
 

Author Comment

by:pratap_surisoft
ID: 10647639
Hi All thanks again for your time spent on this question.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question