Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello, Here I did the code for button click event from where I pass the value browseurl and browsingitem. I want to pass these values when I call the function wc_DownloadStringCompletedbrowse, but it showing error. The click button is :

C#
browsebutton.Click += new EventHandler((sender1, e1) => browsebutton_Click(sender, e, browseurl, browsingitem));
On its click event I did this code, but is showing error on 'browsebutton_Click' in line(private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem))
and error is:
C#
private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem)
{
    WebClient wc = new WebClient();
    wc.DownloadStringAsync(new Uri("http://dev.livestuff.com/" + browseurl));
    wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);
}

void wc_DownloadStringCompletedbrowse(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem)
{
    var serializer = new JavaScriptSerializer();
    serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
    dynamic obj = serializer.Deserialize(e.Result, typeof(object));
}


Please give me any code through which I can pass the value of browseurl and browsingitem.
Thanks.
Posted
Updated 3-Apr-14 0:14am
v2

browsebutton_Click() is defined to return something of type object. In the method's code, there is no return statement.

Return something or, if nothing is to be returned, change the method's return value to void.
 
Share this answer
 
Comments
Thomas Daniels 3-Apr-14 6:18am    
You beat it to me! +5!
Priyanka Bhawsar 3-Apr-14 6:40am    
Thanks but now its showing error 'Cannot implicitly convert type 'void' to 'object'' on line (wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);)
lukeer 3-Apr-14 7:27am    
Puzzling.
The MSDN says about the WebClient.DownloadStringCompleted event that it can be subscribed using methods matching the DownloadStringCompletedEventHandler delegate, which is defined to return void. Your code seems to match that requirement exactly.

Sorry, I'm of no help here.
You get the error because you don't return any value using a return statement. If you don't need to return something, change object into void in your method:
C#
private void browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem)

If you need to return something, use a return statement at the end of your method:
C#
return theObjectThatYouWantToReturn;


[Edit]

You said in your comment that you have still a problem. Here is how to fix it:
C#
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler((sndr, ev) => wc_DownloadStringCompletedbrowse(sndr, ev, browseurl, browsingitem));
 
Share this answer
 
v2
Comments
Priyanka Bhawsar 3-Apr-14 6:49am    
Thanks but now its showing error 'Cannot implicitly convert type 'void' to 'object'' on line (wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);)
Thomas Daniels 3-Apr-14 6:54am    
I'm looking for a solution.
Thomas Daniels 3-Apr-14 7:02am    
I updated my answer. Look at the part after the [Edit]
Priyanka Bhawsar 3-Apr-14 7:20am    
I tried this code but through this control is not going to this code ie functinon is not calling.
void wc_DownloadStringCompletedbrowse(object sender, DownloadStringCompletedEventArgs e,dynamic browseurl, int a)
{

var serializer = new JavaScriptSerializer();
serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
dynamic obj = serializer.Deserialize(e.Result, typeof(object));
dynamic obj1 = obj[0];

}
Thomas Daniels 3-Apr-14 8:09am    
If I try it, the function is calling, so probably the problem is a problem with your serializer. But I have no idea about JavaScript serializers, so I can't help you further. I'm sorry.
Hi,

Quote:
private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem)
{
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://dev.livestuff.com/" + browseurl));
wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);
}


Your browsebutton click method definition has return type as object but you haven't return any object so it is giving error.

try as below

C#
private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem)
{
    WebClient wc = new WebClient();
    wc.DownloadStringAsync(new Uri("http://dev.livestuff.com/" + browseurl));
    return wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);
}



Thanks,
-RG
 
Share this answer
 
v2
Comments
Priyanka Bhawsar 3-Apr-14 6:49am    
Thanks but now its showing error 'Cannot implicitly convert type 'void' to 'object'' on line (wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);)
Ramug10 3-Apr-14 8:10am    
I have updated my solution try it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900