user3079575
user3079575

Reputation: 19

I am getting Input string was not in a correct format although i used the same format over and over again

Input string was not in a correct format. I dont know why, i've used this format before, i guess i'm missing something

 StringBuilder sb = new StringBuilder(); 

  for (int i = 0; i < 3; i++)
            {
                sb.Append(string.Format(@"
                <button onclick=""playPause{0}()"" type=""button"" >Play/Pause</button> 
                <br> 
                <video id=""video{0}"" width=""420"" controls>
                <source src=""videos/arturo.mp4"" type=""video/mp4"">
                <source src=""videos/arturo.ogg"" type=""video/ogg"">
                Your browser does not support HTML5 video.
                </video>
                <script type=""text/javascript"" > 

                function playPause{0}()
                { 
                var myvideo = document.getElementById('video{0}');
                if (myvideo.paused) 
                myvideo.play(); 
                else 
                myvideo.pause(); 
                } 

                </script> 
   ", i));
  }

            Literal1.Text = sb.ToString();

Upvotes: 1

Views: 1212

Answers (1)

Steve
Steve

Reputation: 216333

You need to double the curly braces

....
function playPause{0}()
{{ 
var myvideo = document.getElementById('video{0}');
if (myvideo.paused) 
myvideo.play(); 
else 
myvideo.pause(); 
}} 
....

Otherwise the string format interpret them as placeholder for the next argument, that you don't supply in the argument list (It is like you do for the double quotes)

Upvotes: 2

Related Questions