2012-02-26 62 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

相關問題