473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C#-Web - Convert System.Web.UI.WebControls to String

All,
I have some C# code doing some form processing for me. Some forms have a certain control, some don't. If the control exists i need to do some processing on it later.
Of course when i try to process the variable on pages that don't have it i get compiler errors. To get around that someone recommended I use FindControl like below.
Unfortunately now I can't get the value found into the string variable I use to do my later processing.
I'm not a full time programmer and it's not my my area of expertise, but there's gotta to be a way to do what i want.
Expand|Select|Wrap|Line Numbers
  1. RadioButton rb_test = Page.FindControl("rb_monthly") as RadioButton; 
  2.         if (rb_test != null) { 
  3.         monthly = (string)rb_test;
  4.         } 
monthly is the string value i need for later comparisons. rb_monthly is the sometimes used variable that i need to get data from.
Thanks for any and all help!!
Nov 27 '07 #1
5 3185
nateraaaa
663 Expert 512MB
All,
I have some C# code doing some form processing for me. Some forms have a certain control, some don't. If the control exists i need to do some processing on it later.
Of course when i try to process the variable on pages that don't have it i get compiler errors. To get around that someone recommended I use FindControl like below.
Unfortunately now I can't get the value found into the string variable I use to do my later processing.
I'm not a full time programmer and it's not my my area of expertise, but there's gotta to be a way to do what i want.
Expand|Select|Wrap|Line Numbers
  1. RadioButton rb_test = Page.FindControl("rb_monthly") as RadioButton; 
  2.         if (rb_test != null) { 
  3.         monthly = (string)rb_test;
  4.         } 
monthly is the string value i need for later comparisons. rb_monthly is the sometimes used variable that i need to get data from.
Thanks for any and all help!!
So you want the text of the radiobutton? If that is the case try setting monthly = to the following:

monthly = rb_test.Text;

Nathan
Nov 27 '07 #2
Plater
7,872 Expert 4TB
Just like any control, you will want to access the .Text property for the text string.
Please remember to check MSDN, or hit ctrl+space in visual studio to see available options.
Nov 27 '07 #3
Thanks for the help so far, what you have said makes sense, unfortunately it's not working. Earlier on in the code Monthly is predefined as false and when i output the value i still get false even though i set it to true on the form

Here is what I did with your assistance
Expand|Select|Wrap|Line Numbers
  1. RadioButton rb_test = Page.FindControl("rb_monthly") as RadioButton; 
  2.         if (rb_test != null) { 
  3.         monthly = rb_test.Text;
  4.  
  5.         }
Here is what I know works(but of course only when the control actually exists):
Expand|Select|Wrap|Line Numbers
  1.     if(rb_monthly != null)
  2.             {
  3.                 monthly = rb_monthly.SelectedValue;
  4.             }
  5.  
Thanks again
Nov 27 '07 #4
nateraaaa
663 Expert 512MB
Thanks for the help so far, what you have said makes sense, unfortunately it's not working. Earlier on in the code Monthly is predefined as false and when i output the value i still get false even though i set it to true on the form

Here is what I did with your assistance
Expand|Select|Wrap|Line Numbers
  1. RadioButton rb_test = Page.FindControl("rb_monthly") as RadioButton; 
  2.         if (rb_test != null) { 
  3.         monthly = rb_test.Text;
  4.  
  5.         }
Here is what I know works(but of course only when the control actually exists):
Expand|Select|Wrap|Line Numbers
  1.     if(rb_monthly != null)
  2.             {
  3.                 monthly = rb_monthly.SelectedValue;
  4.             }
  5.  
Thanks again
So you want the value of the radiobutton not the text of the radiobutton. You are on the right track but you need to create a new control and assign it the value of rb_monthly.

Expand|Select|Wrap|Line Numbers
  1. RadioButton rb_test = Page.FindControl("rb_monthly") as RadioButton; 
  2.         if (rb_test != null) { 
  3.         monthly = rb_test.SelectedValue;
  4.  
  5.         }
Nathan
Nov 27 '07 #5
Finally got it!! The problem was I was think in HTML terms, instead of asp.net, I need to use RadioButtonList instead of Radio Button!

THANKS!!!
Nov 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
8
by: FrzzMan | last post by:
How to convert back a string that have converted to byte using System.Text.Encoding.UTF8.GetBytes() string StringData = "This is a string"; byte ConvertedString =...
0
by: R. John Reed | last post by:
Hi All, I'm am looking to convert a currency string (e.g. "$1,234.56" to a double value). It appears this will work: double val = Convert.ToDouble(Double.Parse­("$123,456.78901",...
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
0
by: RSH | last post by:
I am having a bit of trouble filling a datatable with a query. I'm getting the error message: System.FormatException: String was not recognized as a valid DateTime. at...
2
by: UJ | last post by:
I have need to convert a text string (with formatting) to an image. This is so that I can resize the image to different sizes and the formatting stays exactly the same regardless of the size. I...
2
by: Imran Aziz | last post by:
Hello All, How can I convert System.Byte to System.String ? When I use Convert.ToString() it just returns me the string "System.Byte" Please help me out with this. Imran.
0
by: Qiang | last post by:
Anybody knows how to convert convert System.Windows.Forms.HtmlDocument to String? Any API or sample code will be greatly appreciated. thanks, Qiang
8
by: =?Utf-8?B?UmljYXJkbyBRdWludGFuaWxsYQ==?= | last post by:
i need to convert data from string to nibble wich (nibble is a four bits representation) As example i have the following code string data1 = "12345678"; so ¿how can i convert this data...
3
by: DaveRook | last post by:
Hi I've had a few error messages with this I don't understand why. It works fine in a Windows Form, but now moving it to a website, it's not working. I don't have the option to count the lines as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.