开发者

Set class property at runtime

开发者 https://www.devze.com 2023-02-03 14:20 出处:网络
I have a problem with my code, I cannot get it the \'test\' to get the values im trying to assign to it.

I have a problem with my code, I cannot get it the 'test' to get the values im trying to assign to it.

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();

I am trying 开发者_开发技巧to get this to pop up in a dialog box to show that it is working, with something like test.account getting showed in the message box, not sure quite what the problem is.

My overall problem is I am trying to set the class porpert at runtime.

Any help is appreciated.


Is "Record" an existing class?

Is this a compile time error and what does the error say?

One simple solution might be to debug into this using visual studio and check the values there, (if your using Visual Studio).


If you're trying check these values at run time (not development time) then you could use javascript to display a message.

Thanks to a WebProNew.com article...
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);
       }
    }
}

Usage...

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");
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消