tags:

views:

58

answers:

2

No idea why but when I place my custom control in my .aspx page, it's rendering the ID out also. So Consequently, I'm writing out some JavaScript to the page also and right in the middle I get this name of my control so it's messing up my JavaScript.

So in my .aspx I have:

<pm:Car ID="ProductCar" runat="server"/>

And here's what starts to get rendered:

<script type="text/javascript">
var ctl00_mainContent_ProductCar
lastProductID;var ctl00_mainContent_ProductCar
carSize;
...

as you can see ctl00_mainContent_ProductCar is the ID and it's being rendered right after var so I end up with a lastProductID not found error in my JavaScript because the text ctl00_mainContent_ProductCa is in the way.

(updated)

    protected override void Render(HtmlTextWriter writer)
    {
        writer.Write(BuildCarJavaScript());
    }

simply outputs a bunch of JavaScript to the page. And nowhere in my JavaScript do I have it just outputting clientID by itself like I'm seeing.

In BuildCarJavaScript here is where I'm creating that code:

        carJavaScript.Append(@"<script type=""text/javascript"">" + "\r\n");
        carJavaScript.AppendFormat("var {0}lastProductID;", this.ClientID + "\r\n");
...
A: 

This is a problem with the control. How could anyone here help you without seeing how the control is written?

John Saunders
Because I have no idea if it's a familiar problem with all custom controls or something specific to my own code. So I posted it here to see if it's a known issue outside my code first.
CoffeeAddict
Bad mistake. Always blame yourself first. If it's somebody else's fault, there may be nothing you can do about it. But you can fix your own bug if it's your fault. BTW, for the future, a big clue would have been that you knew you were rendering the script you were complaining about.
John Saunders
A: 

Not sure exactly what you expected. This line:

carJavaScript.AppendFormat("var {0}lastProductID;", this.ClientID + "\r\n");

Is going to produce exactly what you're seeing. I guess it might be better to ask; what did you want this to produce?

CAbbott
oh sh** I finally see it now.. I wanted to append a line return AFTER the variable. Duh.
CoffeeAddict
here we go: carJavaScript.AppendFormat("var {0}lastProductID;", this.ClientID).Append("\r\n"); Did not know I could/should chain it like this
CoffeeAddict
lol - happens to the best of us. sometimes it takes laying it out to someone else too see what's wrong.
CAbbott