Page and User Control Communication?

G

Guest

I have a aspx page with one user control , in the user control i have hidden
field (name hdnSaved) runat server wrapped in property like following :-


in documentview.ascx
public string SaveClicked
{
get
{
return (hdnSaved == null) ? "" : hdnSaved.Text;
}
set
{
hdnSaved.Text = value;
}
}


inside aspx page
declaration of UC
protected DocumantViewer Documentview1;


private void Page_Load(object sender, System.EventArgs e)
{
//here when I called Documentview1.SaveClicked while debug and I put the
//breakpoint in the user control get section the hdnSaved set as (undefined)
why???
if(Documentview1.SaveClicked == "true" || Documentview1.SaveClicked == "")
{
//do something
}
else
{
Documentview1.ShowFolder();
}

}
 
K

Karl Seguin

Raed:
Simple question, but you do have
protected HtmlInputHidden hdnSaved;

declared in the documentview.ascx.cs (codebehind) and <input type="hidden"
runat="server" id="hdnSave" /> in the aspx?

Karl
 
E

Elton Wang

Hi Raed,

You only declare the usercontrol but not assign any
reference to it. So it's null (undefined). In order to use
it, you have to get its reference. You can get its
reference from its Control ID. In aspx page look at HTML
code, find something like
<uc1: Documentview1 id="Documentview11"
runat="server"></uc1: Documentview1>.

So the ID is Documentview11.

In Page_Load
Documentview1 = (Documentview)this.FindControl
("Documentview11");
// Then you can use the Documentview1

HTH

Elton Wang
(e-mail address removed)
-----Original Message-----
I have a aspx page with one user control , in the user control i have hidden
field (name hdnSaved) runat server wrapped in property like following :-


in documentview.ascx
public string SaveClicked
{
get
{
return (hdnSaved == null) ? "" : hdnSaved.Text;
}
set
{
hdnSaved.Text = value;
}
}


inside aspx page
declaration of UC
protected DocumantViewer Documentview1;


private void Page_Load(object sender, System.EventArgs e)
{
//here when I called Documentview1.SaveClicked while debug and I put the
//breakpoint in the user control get section the hdnSaved set as (undefined)
why???
if(Documentview1.SaveClicked == "true" ||
Documentview1.SaveClicked == "")
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top