Renaming a button from a string - asp.net

I am trying to rename a button from a string. Sounds simple enough? Well I have scowered the internet and tried many things however I keep coming up with the same errors.
I have 2 forms and one class file. I am using object orientation to pass a string from a textbox to form1 where upon the "button1.Text" can be change passing it through my "Reference class" (I don't think it can be done any other way)
private void button1_Click_1(object sender, EventArgs e)
{
Refclass Ref = new Refclass();
String but1 = Ref.but1;
String btn = "button1"; this.Controls[btn].Text = but1;
}
I am sure this is probably wrong but I hope by this might be able to understand what I am trying to do. I am calling a string from the "Ref" class and calling the string "hell"
Needless to say I am either getting a debugging error and totally crashing visual studio or I get an error saying "Object reference not set to an instance of an object."
I know I am going wrong somewhere does anyone know where? Thank you.

there is no need of create the object for class.if your class in same assembly.just call like this.
button1.text=ref.but1;
where but1 is a const string in that class.

Related

Extending SyndicationItem in VB.net

I need your help for an issue about inheritance.
In a project of mine I am using a the SyndicationFeed .net class to read several feed a make a ul of its elements.
For every element I want to show the feed's image as well, so I wanted to assign the same ImageUrl property of the feed to the single item.
So I started by creating a derived class:
Public Class SyndicationItemWImage
Inherits SyndicationItem
Private mItemImage As Uri
Public Property ItemImage As Uri
Get
Return mItemImage
End Get
Set(value As Uri)
mItemImage = value
End Set
End Property
End Class
Then I would initialize the object and populate it
Dim BlogsPostsWImage As List(Of SyndicationItemWImage)
BlogsPostsWImage = New List(Of SyndicationItemWImage)
…
[initialize SyndFeed]
…
BlogsPostsWImage.AddRange(SyndFeed.Items.ToList.GetRange(0, 10))
Where SynFeed is a well working SyndicationFeed object.
Unfortunately I get an error that the cast is invalid:
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List1[System.ServiceModel.Syndication.SyndicationItem]' to type 'System.Collections.Generic.IEnumerable1[lucamauricom.SyndicationItemWImage]'. at lucamauricom._default.Page_Load(Object sender, EventArgs e)
I do not understand why: shouldn't the cast from a parent class to a child one be allowed?
I think I am missing something fundamental here… not sure what.
Thanks for any help you can provide.
Unfortunately nobody appears to be able to help me with this, so I went on attacking the problem from another angle: I now have an alternative method to accomplish the same goal. I am answering my own question here to document it.
Starting from the same SynFeed as above, I filled a temporary List and then I added an ElementExtension:
Dim TempItems As New List(Of SyndicationItem)
If SyndFeed.Items.Count >= CurrentFeed.TotalElements Then
TempItems.AddRange(SyndFeed.Items.ToList.GetRange(0, CurrentFeed.TotalElements))
Else
TempItems.AddRange(SyndFeed.Items.ToList)
End If
For Each CurrItem As SyndicationItem In TempItems
CurrItem.ElementExtensions.Add("favico", "", SingleFeed.Descendants("//bits.wikimedia.org/favicon/wikipedia.ico")
Next
FeedItems.AddRange(TempItems)
The ElementExtension is called favico, it contains no namespace and has value //bits.wikimedia.org/favicon/wikipedia.ico.
This way, I added the data as a sort of "custom field" that can be easily read on the ASPX page like this:
<img src='<%#CType(Container.DataItem, SyndicationItem).ElementExtensions.ReadElementExtensions(Of String)("favico", "").Item(0).ToString%>' height="16" />
I still cannot figure out what is wrong with the derived class of my original idea, but this second way of dealing with the issue is probably better within the context of Syndication class.

Problem with dotnetopenauth client.ProcessUserAuthorization()

I downloaded DotNetOpenAuth-3.5.0.10259 and tried to run the samples, specifically the OAuthClient sample and I managed to get it to work with facebook (VS2010). I can see "Welcome, [my name]" after allowing access in facebook.
The problem comes in when I try to use it in another project. I get a "No overload for method 'ProcessUserAuthorization' takes '0' arguments" and "No overload for method 'RequestUserAuthorization' takes '0' arguments".
Its basically the same code, which I find very weird since it works on the included sample but won't compile in the other project.
What did I miss?
protected void Page_Load(object sender, EventArgs e)
{
IAuthorizationState authorization = client.ProcessUserAuthorization();
if (authorization == null)
{
// Kick off authorization request
client.RequestUserAuthorization();
}
private static readonly FacebookClient client = new FacebookClient
{
ClientIdentifier = ConfigurationManager.AppSettings["facebookAppID"],
ClientSecret = ConfigurationManager.AppSettings["facebookAppSecret"],
};
The FacebookClient class came from the DotNetOpenAuth.ApplicationBlock project in the samples included in the 3.5.0.10259 download.
The only thing I can guess is that there is missing overload definitions within the libraries. I experienced the same issue you are describing, but in my case I couldn't get the samples to compile at all.
The trick though, is to simply pass in a NULL for the request parameter, which seems to work:
IAuthorizationState authorization = client.ProcessUserAuthorization(null);
Also note that you may run into the same missing overload issue with the "RequestUserAuthorization" method. Likewise, you can also pass in null values for each of the three parameters if you don't want to send them along:
client.RequestUserAuthorization(null, null, null);
Good luck!

Can somebody please explain this common binding pitfall to me? (using the wrong bindable event name)

I refer to this site link text
Using the wrong event name in the
[Bindable] tag can cause your
application to not bind your property,
and you will not even know why. When
you use the [Bindable] tag with a
custom name, the example below looks
like a good idea:
public static const EVENT_CHANGED_CONST:String = "eventChangedConst";
private var _number:Number = 0;
[Bindable(event=EVENT_CHANGED_CONST)]
public function get number():Number
{
return _number;
}
public function set number(value:Number) : void
{
_number = value;
dispatchEvent(new Event(EVENT_CHANGED_CONST));
}
The code above assigns a static
property to the event name, and then
uses the same assignment to dispatch
the event. However, when the value
changes, the binding does not appear
to work. The reason is that the event
name will be EVENT_CHANGED_CONST and
not the value of the variable.
The code should have been written as
follows:
public static const EVENT_CHANGED_CONST:String = "eventChangedConst";
private var _number:Number = 0;
[Bindable(event="eventChangedConst")]
public function get number():Number
{
return _number;
}
public function set number(value:Number) : void
{
_number = value;
dispatchEvent(new Event(EVENT_CHANGED_CONST));
}
I agree, the wrong example does look like a good idea and I would do it that way because I think it's the right way and avoids the possibility of a typing error. Why is the name of the constant used instead of it's value? Surely this can't be right?
I appreciate your insights
Because the standard Flex compiler isn't that clever at times... and I feel your pain! I've complained about this exact problem more than a few times.
If I remember correctly, it's because the compiler does multiple passes. One of the early passes changes the Metadata into AS code. At this point in the compiler it hasn't parsed the rest of the AS code, so its not capable of parsing Constants or references to static variables in other files.
The only thing I can suggest is sign up to the Adobe JIRA, vote for the bug, and hope that the compiler fixes in 4.5 bring some relief.

How can I emulate ErrorProvider in .NET Compact Framework?

Since there is no ErrorProvider class in .NETCF, how can I implement similar functionality (not necessarily exactly like ErrorProvider)?
I am using all the regular databinding constructs to bind controls to a datatable, using the DataRow.RowError property and DataRow.SetColumnError method, but I can't find events on any of DataTable, BindingManagerBase, etc. that I can hook into to receive any sort of notification.
Am I stuck calling a method to manually iterate through all the controls on my form and change some look/feel of the bound control?
Thanks,
MrB
The ErrorProvider class seems pretty basic - actually, a little too basic. If you have Red Gate Reflector, I would recommend disassembling the class and looking at it. Otherwise, create a Dictionary<Control, String>.
Here is a quick idea on creating your own provider:
Dictionary<Control, String> ErrorSet = new Dictionary<Control, String>();
public void SetError(Control control, String message)
{
// code for adding error information
ErrorSet.Add(control, message);
}
public String GetError(Control control)
{
// code for retrieving error information
return ErrorSet[control];
}
public String Clear()
{
// code for clearing all errors
}
I don't have R-G reflector here or I would provide more sample methods. But this ought to provide some sort of sample to work from.

best way to store / lookup name value pairs

I have a list of error codes I need to reference, kinda like this:
Code / Error Message
A01 = whatever error
U01 = another error
U02 = yet another error type
I get the Code returned to me via a web service call and I need to display or get the readable error. So I need a function when passed a Code that returns the readable description. I was just going to do a select case but thought their might be a better way. What is the best way / most effieient way to do this?
Use a Dictionary, (in C#, but the concept and classes are the same):
// Initialize this once, and store it in the ASP.NET Cache.
Dictionary<String,String> errorCodes = new Dictionary<String,String>();
errorCodes.Add("A01", "Whatever Error");
errorCodes.Add("U01", "Another Error");
// And to get your error code:
string ErrCode = errorCodes[ErrorCodeFromWS];
You would use a dictionary. A dictionary uses a hashmap internally for performance, so it is good in that regard. Also, because you want this to go as quickly as possible by the sounds of it, I would statically initialize it in its own class instead of, for example, in an XML file or slimier. You would probably want something like:
public static class ErrorCodes
{
private static Dictonary<string, string> s_codes = new Dicontary<string, string>();
static ErrorCodes()
{
s_codes["code"] = "Description";
s_codes["code2"] = "Description2";
}
public static string GetDesc(string code)
{
return s_codes[code];
}
}
That way, if you wanted to move the back end to a file instead of being static, then you could.

Resources