PlaceHolder question Asp/C#

T

Tony!

With the code below, if I click RadioButton1, It shows the two images,
one on top of the other.

If I take the 2nd image code out of the RadioButton1's event and put
the code for the 2nd image into it's own option button ( RadioButton2)
code, the image then replaces the previous image instead of 'adding"

I'm guessing it has to do with scope, but how would I keep adding to
the placeholder.controls in code?

(This is a bad example, I know, my plan is to use checkboxes instead
of radiobuttons, but I'm just testing/learning at the moment with this
code)

In my. aspx file:
<td valign="top" width="50%">
<asp:placeHolder ID="PlaceHolder1"
runat="server"></asp:placeHolder>
</td>



in my .cs file:
protected void RadioButton1_CheckedChanged(object sender,
EventArgs e)
{

System.Web.UI.WebControls.Image img1; //Image

img1 = new System.Web.UI.WebControls.Image();
img1.ImageUrl = "~/Images/Pic1.png";

img1.ID = "img1";
img1.ToolTip = "This is an image";
//To set height and width of image
img1.Height = Unit.Pixel(110);
img1.Width = Unit.Pixel(1024);
PlaceHolder1.Controls.Add(img1);


System.Web.UI.WebControls.Image img2; //Image

img2 = new System.Web.UI.WebControls.Image();
img2.ImageUrl = "~/Images/Pic2.png";

img2.ID = "img2";
img2.ToolTip = "This is an image";
//To set height and width of image
img2.Height = Unit.Pixel(110);
img2.Width = Unit.Pixel(1024);
PlaceHolder1.Controls.Add(img2);
}


Any suggestions welcome :)

Thanks,

Tony!
 
T

Tony!

With the code below, if I click RadioButton1, It shows the two images,
one on top of the other.

If I take the 2nd image code out of the RadioButton1's event and put
the code for the 2nd image into it's own option button ( RadioButton2)
code, the image then replaces the previous image instead of 'adding"

I'm guessing it has to do with scope, but how would I keep adding to
the placeholder.controls in code?

(This is a bad example, I know, my plan is to use checkboxes instead
of radiobuttons, but I'm just testing/learning at the moment with this
code)
Any suggestions welcome :)

Thanks,

Tony!


Googling leads me to having to save the viewstate of the controls in
order to have them survive a postback or page refresh, but I haven't
figured out the syntax for this in my code.

I've set EnableViewState = true in my aspx file for the various image
and option button controls, but I'm still having trouble understanding
the examples I've seen so far

Tony!
 

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,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top