473,322 Members | 1,398 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,322 software developers and data experts.

getting a element name out of a variable...

Hello all, and thank you in advance for any feedback/help you might post.

I need help getting a web page element id out of a string variable to be used within my c# code behind page.

I am trying to display a string in a literal control telling the user what was wrong with the input that they provided in the associated text box. my error string looks like this:
Expand|Select|Wrap|Line Numbers
  1. errorMsg = "litLastName-Please enter a valid last name"
  2.  
I already have the string split and placed into two variables. this happens in a for loop.

here is my code thus far in C#:
Expand|Select|Wrap|Line Numbers
  1. {
  2.                 string errorMsg = hdnErrorMsg.Value;
  3.                 litResults.Text = errorMsg;
  4.  
  5.                 //breaks up the mass error string into individual error strings
  6.                 string[] errorMsgSplit = errorMsg.Split('/');
  7.                 string strLitErrorElement = "";
  8.                 string strLitErrorMsg = "";
  9.  
  10.                 for (int i = 1; i < errorMsgSplit.Length; i++)
  11.                 {
  12.                     strLitErrorMsg = strLitErrorMsg + errorMsgSplit[i];
  13.                     litResults.Text = strLitErrorMsg;
  14.  
  15.                     //splits the individual error strings into the asp lit and lit text
  16.                     string[] indErrorMsg = errorMsgSplit[i].Split('-');
  17.                     strLitErrorElement = indErrorMsg[0];
  18.                     strLitErrorMsg = indErrorMsg[1];
  19.  
  20.                     (here is the part where I'm stuck)
  21.                 }
  22.             }
  23.  
basically i need to get the stuff out of strLitErrorElement out so I can use it like this:
Expand|Select|Wrap|Line Numbers
  1. litLastName.text = "Please enter a valid Last Name"
  2.  
Again, thank you ahead of time for your positive input, help, and/or examples :)
Oct 6 '08 #1
3 1173
Plater
7,872 Expert 4TB
You will have to make some sort of FindControlByName(string name) type function. Loop through all the controls, comparing their Name property to the one you want.
Although, you use a literal control, which isn't really a control at all. (Doesn't end up as a DIV or a SPAN or any other html, just plain text) Are you just using them to provide a "layout" so your error messages show up next to the control that is incorrect?
Oct 6 '08 #2
You will have to make some sort of FindControlByName(string name) type function. Loop through all the controls, comparing their Name property to the one you want.
Although, you use a literal control, which isn't really a control at all. (Doesn't end up as a DIV or a SPAN or any other html, just plain text) Are you just using them to provide a "layout" so your error messages show up next to the control that is incorrect?

pretty much. I want to use a loop instead of coding all of the literals individually because I'd like to use this on a form that has 55+ different inputs. thanx for the quick response.
Oct 6 '08 #3
Got it working. here is the updated code:
Expand|Select|Wrap|Line Numbers
  1. string errorMsg = hdnErrorMsg.Value;
  2.  
  3. //breaks up the mass error string into individual error strings
  4. string[] errorMsgSplit = errorMsg.Split('/');
  5.  
  6. for (int i = 1; i < errorMsgSplit.Length; i++)
  7. {
  8.     //splits the individual error strings into the asp lit and lit text
  9.     string[] indErrorMsg = errorMsgSplit[i].Split('-');
  10.  
  11.     Literal litError = (Literal)FindControl(indErrorMsg[0]);
  12.     litError.Text = indErrorMsg[1];
  13. }
  14.  
Thanx!
Oct 7 '08 #4

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

Similar topics

4
by: Jean-Christophe Michel | last post by:
Hi, In a complex merging of two (non ordered) xml files i need to keep track of the elements of the second tree that were already merged with first tree, to copy only unused elements at the end....
9
by: Stefan Franke | last post by:
Hi, I've got the following simple XSLT stylesheet, that lists all the values of the elements of any given XML file. <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0"...
3
by: Mr. x | last post by:
Hello, I have simple table <table id = "mytable" ....> .... </table> I want to get the left position of the table. Everything I did getting wrong :
10
by: darrel | last post by:
I have this structure: mypage.aspx (class = mypage) myusercontro.ascx On the mypage.aspx I can declare a variable: animal = "monkey" I can read this from the UC by simply doing this:...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
1
by: robing | last post by:
I am having trouble getting data from a text input field element. the element is called amount_$counter with $counter being the row of the table. when i have made an input to the text field and...
5
by: Kniffel | last post by:
Hi everyone I do a xsl-transformation. And I try to get a Attribute, but I cannot get it. My XML/XSL experience is not very good at the moment. I have something like this: TEST.xml...
1
by: bhavanirayala | last post by:
Hi, I am sending the values from one method to another method to get the values from xml file based on the inputs. I am getting the error like:: Variable "$collType" will not stay shared...
3
markmcgookin
by: markmcgookin | last post by:
Hi, I have the following XML <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd"> <DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved> <UserName>Bob</UserName>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.