How to control a User Control?

  • Thread starter Thread starter Bruce W.1
  • Start date Start date
B

Bruce W.1

I've got a User Control which has a bunch of buttons for navigating.
When clicked they do a Server.Transfer to another page in the application.

How do I make the clicked nav button look different? Let's say I simply
want to change its background color.

Would the code to implement this be in the User Control's code-behind,
or in the code-behind of the page that's using the User Control? From
where does one access and control the User Control? How is this done?

Thanks for your help.
 
Tim said:
UC are self-contained, therefore you could set the properties on the UC itself. (however note that UC do inherit the page CSS).




Depends for what. If you want the UC to do something upon clicking a button in the UC, that is done in the UC itself - in some sense UC are just like self-contained ASPX pages. Drag the button onto the UC, double click it, and put the code there. Drag the UC onto an ASPX page. Run the page. When the user clicks the UC button, that code will be run.

HTH,
Tim Stall
==========================================================

I have a web page called SomePage.aspx which uses a UC for navigation.

The name of the UC is navUC.ascx.

When SomePage.aspx loads, I need to have one of the buttons in the UC
look different than the others, i.e. the button that represents the page
I am on.

Say my UC buttons are imageButtons. I need to set the source property
of imageButtonX (let's call it) to be different than its default source
image in the UC.

navUC.ascx has no way of knowing what page is using it, so it cannot
make one imageButton have a different image.

So from SomePage.aspx I need to tell navUC.ascx to have imageButtonX use
a different source image.

How is this done?
 
This is how i am doing it
-- Pass query string in your URL (i.e somepage.aspx?myImageButtonFlag=1
-- In the code behind of your User control in Page_Load method add the following logic

// Page_Load method of your USER CONTRO
private void Page_Load(object sender, System.EventArgs e

if (Request["myImageButtonFlag"] != null)

// myImageButtonFlage exists in query strin
// put your required logi

els

// myImageButtonFlage does not exist
// put your required logic her



Thanks

Reza Nab

----- Bruce W.1 wrote: ----

Tim Stall wrote
UC are self-contained, therefore you could set the properties on the UC itself. (however note that UC do inherit the page CSS)
Tim Stal
=========================================================

I have a web page called SomePage.aspx which uses a UC for navigation

The name of the UC is navUC.ascx

When SomePage.aspx loads, I need to have one of the buttons in the UC
look different than the others, i.e. the button that represents the page
I am on

Say my UC buttons are imageButtons. I need to set the source property
of imageButtonX (let's call it) to be different than its default source
image in the UC

navUC.ascx has no way of knowing what page is using it, so it cannot
make one imageButton have a different image

So from SomePage.aspx I need to tell navUC.ascx to have imageButtonX use
a different source image

How is this done
 
Back
Top