带单选按钮的图像控制 [英] image control with radio buttons

查看:72
本文介绍了带单选按钮的图像控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,
我需要一个可以容纳图片和两个单选按钮的控件,就像在fb/orkut上上传图片时所拥有的控件一样.
1.图片
2.删除单选按钮.
3.封面单选按钮.[将此图像设置为相册的封面]

我已经用这三样东西创建了一个用户控件.
在单击按钮的aspx页面上,我需要添加此用户控件.
意味着,用户将使用FileUpload选择图像,并且当他单击按钮时,应该加载该用户控件.
我能够加载控件.检查以下代码.

Hi experts,
I need a control which can hold an image and two radio buttons, like the one we have when we upload a pictures on fb / orkut.
1. Image
2. Delete radio button.
3. Cover radio button.[Set this image as cover of album]

i have created a user control with these three things.
On my aspx page on click of a button i need to add this user control.
Means, user will select the image using FileUpload and when he clicks on the button this user control should be loaded.
I am able to load the control. Check the following code.

protected void btnAddURL_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
			//ItemList is an array list used to store the filename.
            ItemList.Add(FileUpload1.FileName);
             showImage();
        }
    }

    public void showImage()
    {
        
        PlaceHolder p = new PlaceHolder();

		//Create Thumbnail
        FileUpload1.SaveAs(@"D:\ASP\Project_Dec_16\RealEstate\SaveImage\" +    FileUpload1.FileName);
        System.Drawing.Image img1 = System.Drawing.Image.FromFile(@"D:\ASP\Project_Dec_16\RealEstate\SaveImage\" + FileUpload1.FileName);
        System.Drawing.Image bmp2 = img1.GetThumbnailImage(100, 100, null, IntPtr.Zero);
        bmp2.Save(@"D:\ASP\Project_Dec_16\RealEstate\SaveImage\thumbnail\L\" + FileUpload1.FileName);

		//Load the images selected by user
        for (int i = 0; i <= ItemList.Count - 1; i++)
        {
            Control MyUserControl;
			// Load user control dynamically
            MyUserControl = LoadControl("MyControl.ascx");
			MyUserControl.ID = &quot;MyUserControl&quot; + cnt++;</pre>
			Image MyImage = (Image)MyUserControl.FindControl("Image1");
			// MyImage.ID = "Image" + cnt;
			MyImage.ImageUrl = "~/SaveImage/thumbnail/L/" + ItemList[i].ToString();
			p.Controls.Add(MyUserControl);
			Panel2.Controls.Add(p);
		}



问题:
1>所有图像都换行了,我希望它们彼此相邻.
2>如何检测单击的单选按钮,因为我有多个图像,并且所有图像都有单选按钮.
3>如何从aspx页面捕获单选按钮的点击?

在Google上搜索,但找不到解决方案. :(
预先感谢.



Problem :
1> All images come on new line i want them next to each other.
2> How to detect which radio button is clicked as i have more than one images, and all have radio buttons.
3> How to capture click of radio button from aspx page?

Searched on google but could not find a solution for this. :(
Thanks in advance.

推荐答案

1>所有图像都换行了,我希望它们彼此相邻.

您是指用户控制吗?默认情况下,图像以行内显示.您可能可以通过设置用户控件的样式来更改其显示方式:style ="display:inline"

2>如何检测单击的单选按钮,因为我有多个图像,并且所有图像都有单选按钮.
3>如何从aspx页面捕获单选按钮的点击?

确保单选按钮的自动回传为true.

UserControl中的事件将不会显示在属性窗口中.您必须手动设置.

用户控制标记:
1> All images come on new line i want them next to each other.

Do you mean the user controls? Images by default display inline. You maybe able to change the way the usercontrol displays by setting it''s style: style="display:inline"

2> How to detect which radio button is clicked as i have more than one images, and all have radio buttons.
3> How to capture click of radio button from aspx page?

Make sure autopostback is true for the radio buttons.

The event in the UserControl will not show up in the properties window. You have to set it manually.

User Control Markup:
<![CDATA[<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="UserControls_WebUserControl" %>
<asp:button id="Button1" runat="server" text="Button" />
<br />
<asp:radiobutton id="RadioButton1" runat="server" autopostback="True" >
    oncheckedchanged="RadioButton1_CheckedChanged" />



后面的用户控制代码:



User Control Code behind:

public partial class UserControls_WebUserControl : System.Web.UI.UserControl
{
    public event EventHandler UC_RadioClicked;
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        if (UC_RadioClicked != null)
            UC_RadioClicked(sender, e);
    }



页面标记:



Page Markup:

<uc1:webusercontrol id="WebUserControl1"  runat="server" onuc_radioclicked="UC_RadioClicked" xmlns:uc1="#unknown" />

后面的页面代码:

protected void UC_RadioClicked(object sender, EventArgs e)
 {
     RadioButton RB = sender as RadioButton;
     Response.Write("Radio button in user control clicked: " + RB.Parent.ID);
 }


这篇关于带单选按钮的图像控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆