2011-01-07 69 views
-1

我有我的代碼有問題,我不能得到它的'測試',以獲取值即時嘗試分配給它。在運行時設置類屬性

rec = new Record(perosn, actually, com, Centre, CCentre); 
webservicename.singleSummary test = new webservicename.singleSummary(); 

test.person = rec.person; 
test.actually = recc.Actually; 
test.com = rec.Com; 
test.Centre = rec.Centre; 
test.CCentre = rec.CCentre; 

webservicename.Feed CallWebService = new webservicename.Feed(); 

我試圖讓這個彈出的對話框中顯示,它正在與類似test.account在消息框中顯示出越來越不肯定相當的問題是什麼。

我的整體問題是我試圖在運行時設置類porpert。

任何幫助表示讚賞。

+0

你的代碼看起來就好了。你有什麼確切的問題?該屬性接收空值/空值?您是否嘗試過調試以查看變量rec的屬性值? – Smur 2011-01-07 16:10:29

+0

不,我得到它的工作感謝您的輸入,雖然!仍然試圖讓它循環結果,然後停在文檔的末尾,如果你知道我的意思,就像每個值的單獨對話框,你點擊確定,然後它提出下一個值,然後當它到達它告訴你的文檔的結尾。 – Ebikeneser 2011-01-07 16:41:24

回答

0

是「記錄」一個現有的類嗎?

這是編譯時錯誤,錯誤是什麼意思?

一個簡單的解決方案可能是使用visual studio進行調試,並檢查那裏的值(如果使用Visual Studio)。


如果您嘗試在運行時(而不是開發時間)檢查這些值,則可以使用javascript顯示消息。

多虧了WebProNew.com文章...
http://www.webpronews.com/expertarticles/2006/11/29/javascript-alertshowmessage-from-aspnet-codebehind

using System.Web; 
using System.Text; 
using System.Web.UI; 

/// 
/// A JavaScript alert 
/// 
public static class Alert 
{ 
    /// 
    /// Shows a client-side JavaScript alert in the browser. 
    /// 
    /// The message to appear in the alert. 
    public static void Show(string message) 
    { 
     // Cleans the message to allow single quotation marks 
     string cleanMessage = message.Replace("'", "\\'"); 
     string script = "alert('" + cleanMessage + "');"; 

     // Gets the executing web page 
     Page page = HttpContext.Current.CurrentHandler as Page; 

     // Checks if the handler is a Page and that the script isn't allready on the Page 
     if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert")) 
     { 
     page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script); 
     } 
    } 
} 

用法......

void btnSave_Click(object sender, EventArgs e) 
{ 
    try 
    { 
    SaveSomething(); 
    Alert.Show("You document has been saved"); 
    } 
    catch (ReadOnlyException) 
    { 
    Alert.Show("You do not have write permission to this file"); 
    } 
}