Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

Compilation error - user control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zeba - 31 May 2007 10:31 GMT
Hi,

I have a user control in which in have the following code :

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="RatingControl.ascx.cs" Inherits="UserControls_RatingControl"
%>
<script type="text/javascript">

function alterRating(rating)
{
   var i;
   var img = document.getElementById("<%=star"+i+".ClientID %>");
   for(i=1;i<=rating;i++)
   {
       var img = document.getElementById("<%=star"+i+".ClientID %>");
       img.src = "~/Images/StarOver.gif";
   }
   for(i=rating;i<=5;i++)
   {
       var img = document.getElementById("<%=star"+i+".ClientID %>");
      img.src = "~/Images/StarOff.gif";
   }
}

I'm getting a compilation error that says :

) expected

Line 11:     var img = document.getElementById("<%=star"+i+".ClientID
%>");

What is the problem ??

Thanks !!
Jon Skeet [C# MVP] - 31 May 2007 11:03 GMT
<snip>

> What is the problem ??

It's not clear to me what you're trying to do. What do you want the
processed script to come out as? Bear in mind that "i" here is a
variable in the JavaScript, not in the .NET code.

(You might get more replies in the ASP.NET group, by the way.)

Jon
sameer.amin.alibhai@gmail.com - 31 May 2007 12:32 GMT
If I can guess what you are trying to do...
first of all, your i that you have within the <%= %> brackets is going
to refer to your codebehind variables (Not the javascript variable).
It almost seems like you are trying to use reflection or something and
get the ClientID of that item

First of all your javascript is referring to the variable i right
after you declare it but it has no value yet!

Maybe you could use an alternative approach of writing this in your
code behind

WriteScript() //Rough C# Code
{
  int i;
   HtmlControl img; // = Page.FindControl("star"+i); // i not
declared yet
   for(i=1;i<=rating;i++)
   {
       img = Page.FindControl("star"+i);
       img.src = "~/Images/StarOver.gif";
   }
   for(i=rating;i<=5;i++)
   {
// same thing here
//        var img = document.getElementById("<%=star"+i+".ClientID
%>");
//       img.src = "~/Images/StarOff.gif";
   }

}

// same thing here
//   var img = document.getElementById("<%=star"+i+".ClientID %>");

tada..

Or if you want to do it from javascript not codebehind, just modify
the above to do the following

REsponse.write("<script type='text/javascript'>");
then in the loop you can stick another Response.Write(...)
then end with Response.Write("</script>")

or alternatively, read about RegisterClientScript Here:
http://www.codeproject.com/aspnet/ClientServer.asp

Sameer Alibhai
Sharp Developer
http://www.SharpDeveloper.Net

> Hi,
>
[quoted text clipped - 32 lines]
>
> Thanks !!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.