PlaceHolder question Asp/C#

  • Thread starter Thread starter Tony!
  • Start date Start date
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!
 
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!
 
Back
Top