Compilation error - user control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zeba

    Compilation error - user control

    Hi,

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


    <%@ Control Language="C#" AutoEventWireup ="true"
    CodeFile="Ratin gControl.ascx.c s" Inherits="UserC ontrols_RatingC ontrol"
    %>
    <script type="text/javascript">

    function alterRating(rat ing)
    {
    var i;
    var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");
    for(i=1;i<=rati ng;i++)
    {
    var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");
    img.src = "~/Images/StarOver.gif";
    }
    for(i=rating;i< =5;i++)
    {
    var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");
    img.src = "~/Images/StarOff.gif";
    }
    }


    I'm getting a compilation error that says :

    ) expected

    Line 11: var img = document.getEle mentById("<%=st ar"+i+".ClientI D
    %>");

    What is the problem ??

    Thanks !!

  • Jon Skeet [C# MVP]

    #2
    Re: Compilation error - user control

    On May 31, 10:31 am, Zeba <coolz...@gmail .comwrote:

    <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

    Comment

    • sameer.amin.alibhai@gmail.com

      #3
      Re: Compilation error - user control

      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.FindContro l("star"+i); // i not
      declared yet
      for(i=1;i<=rati ng;i++)
      {
      img = Page.FindContro l("star"+i);
      img.src = "~/Images/StarOver.gif";
      }
      for(i=rating;i< =5;i++)
      {
      // same thing here
      // var img = document.getEle mentById("<%=st ar"+i+".ClientI D
      %>");
      // img.src = "~/Images/StarOff.gif";
      }

      }

      // same thing here
      // var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");

      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 RegisterClientS cript Here:


      Sameer Alibhai
      Sharp Developer


      On May 31, 5:31 am, Zeba <coolz...@gmail .comwrote:
      Hi,
      >
      I have a user control in which in have the following code :
      >
      <%@ Control Language="C#" AutoEventWireup ="true"
      CodeFile="Ratin gControl.ascx.c s" Inherits="UserC ontrols_RatingC ontrol"
      %>
      <script type="text/javascript">
      >
      function alterRating(rat ing)
      {
      var i;
      var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");
      for(i=1;i<=rati ng;i++)
      {
      var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");
      img.src = "~/Images/StarOver.gif";
      }
      for(i=rating;i< =5;i++)
      {
      var img = document.getEle mentById("<%=st ar"+i+".ClientI D %>");
      img.src = "~/Images/StarOff.gif";
      }
      >
      }
      >
      I'm getting a compilation error that says :
      >
      ) expected
      >
      Line 11: var img = document.getEle mentById("<%=st ar"+i+".ClientI D
      %>");
      >
      What is the problem ??
      >
      Thanks !!

      Comment

      Working...