2012-02-26 83 views
1

即时通讯使用闪烁API进行一些测试,并且在我的代码中更改了一些控件后,我遇到了一个奇怪的问题。ImageButton和runat =服务器属性

当我第一次尝试要求图像我把它们存储在一个图像和每一件事情都很好,但我想对图像做其他东西,所以我尝试使用ImageButton类,我得到一个异常,它已经运行= “服务器”属性。

我编程添加所有控件。

对我来说奇怪的是,Image类并没有给出任何帮助,而是使用了从他那里继承的类。

所以我qustion是:它可能会添加并检查控制是否通过c#代码runat =“服务器”属性?

(对不起,我的英语)

这里是我的一些代码:

protected void Page_Load(object sender, EventArgs e) 
{ 

    string key = "*****************"; 
    string secret = "***********"; 
    MyFlicker myFlicker = new MyFlicker(key, secret); 
    int photoCount = myFlicker.coll.Count; 
    try 
    { 
     string[] urls = myFlicker.GetPhotosURLS(); 
     string[] desc = myFlicker.GetPhotosDescreptions(); 
     string[] Titels = myFlicker.GetPhotosTitle(); 

     Panel[] panels = new Panel[photoCount]; 
     ImageButton[] images = new ImageButton[photoCount]; 
     Label[] descreptions = new Label[photoCount]; 
     Label[] titles = new Label[photoCount]; 

     for (int i = 0; i < photoCount; i++) 
     { 
      panels[i] = new Panel(); 
      images[i] = new ImageButton(); 
      descreptions[i] = new Label(); 
      titles[i] = new Label(); 


      titles[i].Text = Titels[i] + ":כותרת התמונה"; 
      images[i].ImageUrl = urls[i]; 

      if (descreptions[i] != null) 
       descreptions[i].Text ="תיאור התמונה: " + desc[i]; 
      else 
       descreptions[i].Text = "descreption was not found!"; 

      panels[i].ID = "panel" + i; 
      images[i].ID = "image" + i; 
      descreptions[i].ID = "des" + i; 
      titles[i].ID = "titles" + i; 

      panels[i].Controls.Add((Label)titles[i]); 
      panels[i].Controls.Add((Label)descreptions[i]); 
      panels[i].Controls.Add((Image)images[i]); 
      this.Controls.Add((Panel)panels[i]); 




     } 


    } 

    catch (Exception ex) 
    { 
     Response.Write(ex.Message); 
    } 



} 

这里是apsx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Copy_of_galleryControlTest_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    </div> 
    </form> 
</body> 
</html> 
+0

究竟产生错误你所描述的行代码? – 2012-02-26 12:10:29

+0

为什么你不使用中继器或什么? – 2012-02-26 12:17:48

+0

@ShadowWizard它dosnt告诉我一些共鸣和它自己的代码在尝试和赶上。 – samy 2012-02-26 12:38:39

回答

2

做类似下面的代码测试后,我得到这个错误

'Ima'类型的控件'ctl03' geButton'必须放置在窗体标签 与runat =服务器。

然后我从

this.Controls.Add((Panel)panels[i]); 

改为

form1.Controls.Add((Panel)panels[i]); 

现在它是有道理的.. ImageButton的是提交控件(这将提交形式的控制),所以这是为什么呢这个错误,该控件需要是form1的子项,而不是它的外部

另一个解决办法是重写此方法,但我建议第一个

public override void VerifyRenderingInServerForm(Control control) 
{ 
    ; 
} 
+0

我改变了编码与你offerd我的解决方案,但它仍然genreate相同的异常和怪异becuse的代码是在try和catch仍然dosent显示什么样的代码把它的线。 – samy 2012-02-26 12:43:15

+1

工作了!感谢所有的帮助! – samy 2012-02-26 13:40:27