在运行时设置类属性

时间:2011-01-07 14:53:26

标签: c# binding webservice-client

我的代码存在问题,我无法通过“测试”来获取我尝试分配给它的值。

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。

感谢任何帮助。

1 个答案:

答案 0 :(得分: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");
   }
}