[web] Simple User Control Question [ANSWERED]

Started by
1 comment, last by ArchG 18 years, 3 months ago
Hello, I have made a UserControl in ASP.net with the custom property ClientID. My only question (and I feel like an idiot asking) is how to assin this property with a variable. At first I thought I could just do

<Control:UserControl ID=UC1 Client_ID=<%iClientID%> runat=server />
But you can't use the <% %> brackets inside a runat=server thinger. Next I thought I could change the property with &#106avascript. (Another stupid thought) by using a simple

document.getElementById('UC1').Client_ID = iClientID;
But of course that didn't work because &#106avascript can't access that server stuff. So I'm asking you guys now. How can I assign a variable to a UserControl Property? Thanks, ArchG <!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - ArchG on January 4, 2006 2:52:55 PM]<!--EDIT--></span><!--/EDIT-->
Advertisement
The thing that you have to understand, is that you can't script server-side controls using client-side script. That's a definite no-no.

I would have thought you should be able to use <%= in an attribute value though. Try using

<%= iClientID %>

instead.

Failing that, create a member variable for the control in the codebehind class and set the property value in the Page_Load event handler.

Mark
Yeah, apparently you can't have <% %> blocks in a server side tag..(says the error message).

The reason that it didn't work before in the PageLoad section is I didn't know to use the ID as the prefix. I tried using the TagName and the Prefix as a prefix, but neither of those worked.

Thanks Markr

This topic is closed to new replies.

Advertisement