Monday, March 26, 2012

Passing values to a user control

Hi,

I need to pass a value to an user control. If the value is static I know that I can use this syntax

<HEAD:HEADER id="Header2" value="some value" runat="server"></HEAD:HEADER>

and in my user control I created a public variableVALUE

This works fine.

Now I need to pass a value that I receive in my page via Request.Params(), so I try this way:

<HEAD:HEADER id="Header2" value="<%=MyValue%>" runat="server"></HEAD:HEADER>

Where myValue is a public variable in my aspx page. The problem is that I'm getting an error saying I cannot use <% .. %> in a server tag.

Then I tried this:

<HEAD:HEADER id="Header2" value="<%#MyValue%>" runat="server"></HEAD:HEADER>

Now, I don't get the error but I don't get the value in my usercontrol.

Any ideas??

Thank you so much.

SandraUser controls do have this problem. I solved it by setting the value in code-behind.
Hi JimRoss,

May you show me with and example how to solve this problem?

Thanks in advance.

Sasarivera
1> Declare your control in the codebehind (I am showing it in C# style):
blabla.blabla.Header Header2 ;
2> assign the value:
Header2.value = Request.Params["MyValue"];
Hope this helps.
Hi chunshahab,

Thanks for your code, It solved my problem.

Thanks again.

Sasarivera

0 comments:

Post a Comment