【问题标题】:Set class property at runtime在运行时设置类属性
【发布时间】:2011-01-07 14:53:26
【问题描述】:

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

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 之类的内容,但不确定是什么问题。

我的总体问题是我试图在运行时设置类端口。

感谢任何帮助。

【问题讨论】:

  • 您的代码看起来还不错。你得到什么确切的问题?属性接收空/空值?您是否尝试过调试以查看变量 rec 的属性值?
  • 不,我已经得到它的工作感谢您的投入!仍然试图让它循环结果,然后在文档末尾停止,如果你知道我的意思,就像每个值的单独对话框一样,你点击确定,然后它会显示下一个值,然后当它到达它告诉你的文件的结尾。
  • 您的问题不包含您上次评论中的任何内容。如果您想要有意义的答案,您需要通过更多信息来澄清您的问题。

标签: c# binding webservice-client


【解决方案1】:

“记录”是一个现有的类吗?

这是编译时错误吗?错误说明了什么?

一个简单的解决方案可能是使用 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");
   }
}

【讨论】:

  • 这应该是评论,而不是答案
  • @Daniel -- John 需要 50 次代表才能做到这一点。
  • 静态记录rec = new Record();
  • 我现在已经得到它来显示从 csv 文件中读取的结果,但是它只显示 test.account,有没有办法让我也可以遍历整个 csv 和然后停在它的尽头。即 test.account = 0010 "push ok",然后转到下一个 test.commitment = 2000 "push ok", End of csv "push ok"。
  • 谢谢...我以为我找不到“添加评论”... :)
猜你喜欢
  • 2011-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-02
  • 1970-01-01
  • 2011-04-17
  • 2011-04-09
相关资源
最近更新 更多