Exception in String.Format "Input string was not in a correct format"

T

The Crow

if the reason for error is simple, excuse me. but i cant find what the
reason is. Here is the snippet :



string script = String.Format(@"<script src='common.js'
type='text/javascript'></script>

<script language='javascript' type='text/javascript'>

addLoadEvent(initialize);

var {0}_aryInitialValues = new Array();

var {1};

var {2};

var {3};

var {4};

function initialize()

{

{1} = document.getElementById('{1}');

{2} = document.getElementById('{2}');

{3} = document.getElementById('{3}');

{4} = document.getElementById('{4}');

{0}_aryInitialValues = loadOptionValuesToArray({2});

addSubmitEvent(finish);

}

function finish()

{

debugger;

{0}_aryFinalValues = loadOptionValuesToArray({2});

var {0}_aryAddedValues = getNotContainedItemsAsArray({0}_aryFinalValues,
{0}_aryInitialValues);

var {0}_aryDeletedValues = getNotContainedItemsAsArray({0}_aryInitialValues,
{0}_aryFinalValues);

{3}.value = {0}_aryAddedValues.join('|');

{4}.value = {0}_aryDeletedValues.join('|');

}

</script>", this.ClientID, lbLeft.ClientID, lbRight.ClientID,
hdnAddedValues.ClientID, hdnDeletedValues.ClientID);
 
M

Maqsood Ahmed

Hello,
Yes the reason is very simple. You are using braces ('{','}') in the
string to mark the functions' boundries. string.Format method tries to
parse the braces as place holders for the specified strings and fails,
which leads to a FormatException. Try to use {{ and }} when you want to
define the function scope. It will ultimately transform it into single
brace.

HTH. Cheers.

Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top