0

I created a user control for a button because I will be needing to use it multiple times in the application.

<td class = "center" colspan = "4"><uc:Instructions ID="Instructions" runat="server" />

I have this in the ascx file of the button

<asp:Button ID ="btnInstrs" Text ="Instructions" runat ="server" CssClass ="buttonGreen" OnClick ="btnInstrs_onClick"/>

This is the code behind for the user-control

    protected void btnInstrs_onClick(object sender, EventArgs e)
{

}

public void setColorGreen()
{
    btnInstrs.BackColor = System.Drawing.Color.Green;
}

I have this as the CSS

.buttonGreen
{
background-color: green;
}

So far I have this in the code behind in one of the pages I will be needing this button

 Instructions.setColorGreen();

The setColorGreen method is changing the background color to green when I call it. Any idea why using just the CSS isn't doing the job?

Now to my main question.

I want to return some instructions as a popup and some text on the page when the button is clicked. to get those instructions I will need an itemID to look in the DB and get the instructions So if I was doing everything in the source page. In the event handler I would make a D.B call for the item ID and find the instructions and display but because I want to do it using the user control I don't know how to pass in the itemID or anything else as the parameter into the user control event handler.

Any advise as to how I could code the event handler so I can re-use it in different pages to get the instructions(for an itemID) would be greatly appreciated.

MT0
  • 143,790
  • 11
  • 59
  • 117
CoderWazza
  • 27
  • 4

1 Answers1

0

Calling a method in parent page from user control

This answers my second question. Create an event for the user control when clicked. Handle the event in the source page when exposed.

I can use my itemID in the event handler to make necessary database calls and retrieve information and publish the instructions.

I do the same thing for any other pages required.

Still did not understand why CSS isn't setting the background color of the button to Green.

CoderWazza
  • 27
  • 4