views:

255

answers:

1

I have the following code behind that was, until recently, working fine and dandy!

tbxProdAC.Attributes.Add("onclick", "$('#" + GridView1.ClientID  + "').remove();
$('#" + radProdAC.ClientID  + "').attr('checked', true);
$('#" + ddlBuyer.ClientID  + "').val('--Choose Buyer--');
$('#" + ddlSub.ClientID  + "').val('--Choose Sub Category--');
$('#" + ddlProd.ClientID  + "').val('--Choose Product--');");

However, ever since I have introduced the notion of content place holders (from a master page), I am repeated getting the Object Expected error.

Now I understand why this is happening, asp.net is amending the control names to take into account the CPH i.e. $('#ctl00_ContentPlaceHolder1_radBuyer').attr('checked', true);

How do I go about reslving this issue, effectively 'renaming' my asp.net controls to take this into account?

A: 

A couple options...

One, replace control names with script like <%=radProcAC.ClientID%>. This is somewhat messy, but has the advantage of being very easy to implement.

Two, write the ClientIDs into javascript and output this into your page using RegisterClientScript. So that on the client-side you'll have something like this:

var radProdACClientID = 'ctl00_ContentPlaceHolder1_radBuyer';
var ddlBuyerClientID = 'ctl100_ContentPlaceHolder1_ddlBuyer';

Then obviously you'd use these vars rather than the raw control names.

At any rate, this is a very commmon problem and you can find all sorts of articles written about it with a little google search.

Bryan