Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created two radiobuttons using WPF, and one normal button. The processing of files and reading everything done with WCF.

If I choose radiobutton_1 and click the run button, it will display different files. And if I click radiobutton_2 and run btn I will also get different files. But I need the value of radiobuttons to get those different types of files.

I am not able pass the value of radiobutton to a WCF service. Can someone please suggest a way to do it?

What I have tried:

Radio button
C#
Private void radiobutton1_checked(object sender, RouteEventArgs e)
{
    Service.service client= new service.service.("basichttpbindings_Iservice");
    Client.Getradiobuttonvalue(btn1.Content.ToStrinb());
}
}

At WCF I have implemented Getradiobuttonvalue.

At WPF for the Run button I am calling Run().

When I click radiobutton it gets the desired value. But when I call Run() I will not have the values of radio button. But I need that value within Run()...
Posted
Updated 28-Jan-22 0:53am
v3

1 solution

Radio buttons don't have "values". They have a checked status. The way I'd do it is to associated an integer value with each radio button, and pass that "value" to the WCF method.

The easiest way to implement this paradigm is to assign the Tag attribute for each radio button the desired numeric value, and handle the Click event for the radio buttons, and set a property to whatever the Tag value is of the clicked button. At that point, when you handle the Click event for the regular button, you can simply use the property that contains the value from clicking the radio buttons.

Of course, there are other ways to handle this, but they are much more involved, and I don't feel like explaining them.

If you're WCF API requires a string, the radio button Click events could set the property to the Content attribute of the radio button. IMHO, using the content attribute is fraught with danger because sales nazis may make you change that attribute. To mitigate that possibility, you can set the Tag attribute to the desired string value, so that no matter how you label the radio buttons, they will always provide the known values that your WCF service is expecting.
 
Share this answer
 
v2
Comments
DivyaHal 28-Jan-22 6:58am    
I got it. I have solved the issue. Thank you.

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