ASP.NET UserControl Question

E

EdisonCPP

How can I call a function in one UserControl from another?
I have a custom sign in UserControl and another that needs
to display custom information based on the sign in along
the margin. I've been trying things I've found online, but
can't get a definition of the class.

// C#
private void Successful_SignIn()
{
//compile error: OtherControl is not defined
OtherControl control = (OtherControl)Page.FindControl("OtherControl1");
control.ShowCustomInformation();
}

These controls are on a MasterPage.
I have Session variables being setup in the sign in control, but apparently
the 2nd control's Page_Load() is going off before the sign in control.


Thanks,

Steven
 
E

EdisonCPP

Okay, I was able to get it to compile this line:

OtherControl control = (OtherControl)Page.FindControl("OtherControl1");

by adding:

<%@ Register Src="OtherControl.ascx" TagName="OtherControl" TagPrefix="uc1"
%>

to the top of my aspx page, but now it doesn't know that the function
belongs to the control:

control.ShowCustomInformation();
//says 'OtherControl' does not contain a definition for
'ShowCustomInformation'

Thanks,
Steven
 
E

EdisonCPP

I ended up doing a redirect back to the page again so the other control
would have the session variables needed. That worked.
 

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

Top