how to pass the value between the page and user control

R

rose

Hi everyone,

I have a user control on a page within a table that is by default
hidden through javascript. On a button click, I set the table
visibility to inline through an HtmlInputHidden control and users can
see the User Control within it. When I click the Submit button within
the user control, it closes the table because the HtmlInputHidden
control value is now null.

I have made the HtmlInputHidden control public and from the user
control code behind, I have tried passing a value back to it but I get
an error saying [Object reference not set to an instance of an object]

The code on the User control.cs is something like this

ClassPage objClassPage = new ClassPage();
objClassPage.hdnInputControl.Value = "some value";

Can you please suggest how can I pass the value between the page and
user control?

Thankyou
 
M

Microsoft Newsserver

In the HMTL, you need to add the following attributes

runat="server"
id="theIdMustMatchYourDeclarationOnCodeBehind"

HTH
 
M

Michael Nemtsev [MVP]

Hello rose,

You can iterate throug the page control tree and find your control (control.ClientID)
and then set/read values

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


r> Hi everyone,
r>
r> I have a user control on a page within a table that is by default
r> hidden through javascript. On a button click, I set the table
r> visibility to inline through an HtmlInputHidden control and users can
r> see the User Control within it. When I click the Submit button within
r> the user control, it closes the table because the HtmlInputHidden
r> control value is now null.
r>
r> I have made the HtmlInputHidden control public and from the user
r> control code behind, I have tried passing a value back to it but I
r> get an error saying [Object reference not set to an instance of an
r> object]
r>
r> The code on the User control.cs is something like this
r>
r> ClassPage objClassPage = new ClassPage();
r> objClassPage.hdnInputControl.Value = "some value";
r> Can you please suggest how can I pass the value between the page and
r> user control?
r>
r> Thankyou
r>
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top