|
Why are you using a string for the active control?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
You can't just get directly to a TextBox when all you know is its name.
Here is a little snippet that would do something akin to what you want, assuming your class
is a Form or whatever Container that is holding the TextBoxes:
public string GetTextBoxText(string name) {
string text=null;
foreach(Control c in Controls) {
TextBox tb=c as TextBox;
if (tb!=null && tb.Name==name) text=tb.SelectedText;
}
return text;
}
BTW: If some of your TextBoxes are located deeper in the Control hierarchy, you would have to adapt for that.
PS: as Dave said, if you would hold a reference to the ActiveControl, rather than just holding its name, you could get to its text right away!
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Does anyone know the best way to store and access thousands of abbreviations which are stored in a db and output the full string. For example Intel's stock symbol is INTC. When i read INTC from the db i want to set string str to Intel Corporation so the full name can be displayed to the user. currently the full string is not stored anywhere, just output on the fly based on the abbreviation and a million if-else statements
ie.
if(abrev.equals("INTC")) str = "Intel Corporation";
else if(abrev.equals("GOOG")) str = "Google Inc";
....
....
Obviously the wrong way to go about it. Should the full name just be added to the db? could create hash table with abbreviation as key and full string as value. Yes the if-else method works but is awful to look at and hilariously bad. Thanks guys and gals
|
|
|
|
|
MagForJ wrote: Should the full name just be added to the db?
I would say stroe it in the db itself and use a dictionary to find the mapping.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
As an easy alternative, just make it into a switch.
|
|
|
|
|
Hi
As you already mentioned store the abbrevations and the long name in the db. I would suggest using a second table, so that you can use a nested select statement to get the full name. This will enable you to use the full performance power of your relational database.
Regards
Sebastian
|
|
|
|
|
Use Dictionary<string,string>. The code can be the key. This
e.g.
Dictionary<string,string> companies = new Dictionary<string,string>();
companies.Add("INTC", "Intel Corp");
....
string companyName= companies["INTC"];
Note that you can only have one code entry, but the same company name can appear next to multiple codes.
|
|
|
|
|
I don't know why this bugged me, but it does.
MagForJ wrote: if(abrev.equals("INTC")) str = "Intel Corporation";
else if(abrev.equals("GOOG")) str = "Google Inc";
Why abbreviate "Incorporated" in "Google Inc" but not "Corporation" (Corp) in "Intel Corporation"?
|
|
|
|
|
I'd definitely make it data-driven if I were you. Whether or not you should just add a column to an existing table is another matter.
In this particular case I think I'd have a look to see if I could get the data from somewhere and go from there. For example, there may be a free web service that let's you retrieve this. (This could be done at run-time, but web services are quite slow though; you probably don't want to look up a code at a time for a collection, for example.)
If you can get the data, storing it in a new table has some benefits: The descriptive string can potentially be sizeable, and adding a large column to any table, especially a small table (I've no idea what row sizes you have here), can have a significant impact on row size and thus on performance. I don't know what DB you're working with, but SQL Server has 8K pages and yet I've seen a "transaction" table (storing financial transactions, not database transactions!) that had a column defined as nvarchar(500) - that's a 1000 bytes just for this one column. That table could have millions of rows, but SQL Server couldn't get more than 6 records per page thanks to this horrible design error.
However you store the data, if it's not too substantial and you need raw speed, load it into a cache once and you should get great results.
|
|
|
|
|
how to add controls to webform without using placeholder or panel
|
|
|
|
|
Simple.
Solution 1: Add directly to the Page Control
TextBox txt = new TextBox();
txt.ID = "txt1";
this.Page.Form.Controls.Add(txt);
Solution 2:
Create a DIV tag with an ID and Runat = 'Server'
In the code behind, add the dynamic control to the DIV which inturn will be added to the Page Control
TextBox txt = new TextBox();
txt.ID = "txt1";
divAddDynamicControlsHere.Controls.Add(txt);
this.Page.Form.Controls.Add(divAddDynamicControlsHere);
Solution 3: Create a Table with TR & TD. Expose the TD's Id and Runat='Server'
<table>
<tr>
<td id="tdAddDynamicControlsHere" runat="server"></td>
</tr>
</table>
In the code behind, add the dynamic control to the TD which inturn will be added to the Page Control
TextBox txt = new TextBox();
txt.ID = "txt1";
tdAddDynamicControlsHere.Controls.Add(txt);
this.Page.Form.Controls.Add(divAddDynamicControlsHere);
Solution 4: Use literal control
<asp:literal id="LitDynamicControl" runat="server">
In code behind
string controlText = "<html><head></head>";
controlText += "<body><input type='txt' id='txt'></body></html>";
LitDynamicControl.Text = controlText;
Solution 5: Well you know, PLACEHOLDER CONTROL/PANEL
Solution 6:
Using HTTP Modules [ Creating Server Controls at Runtime using HTTP Modules[ ^] ] - By Niladri Biswas
Hope this helps.
Vote me pls
Niladri Biswas
|
|
|
|
|
Thanks for your reply.But this didn't work.My div tag in update panel.
|
|
|
|
|
Hi,
I have developed an application which contains two projects.
It uses xml files which are located inside the bin folder of one of the projects.
When going through the click once, how do I tell the setup to use the xml files inside the bin folder of the project? i.e. Is there a place where I can include the xml files in the click once?
Thanks
|
|
|
|
|
Read this[^]
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Solved.
Thanks
modified on Wednesday, July 1, 2009 8:37 AM
|
|
|
|
|
If there already exist some text in textBox, then
restrict user, so user can not delete/modify that text, but can add(append) text in to textBox. How to do this?
Soppose:
"Quick brown fox jumps" (already present in text box)
so, user can only append text, but can't modify previous text.
like:
"Quick brown fox jumps ......(only from here he can enter/append)"
regards.
|
|
|
|
|
Try handling the KeyPreview event and then check for 'delete/backspace' key when the current text is at a certain length (i.e. the length of the text you want to always be present). That might work
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: (i.e. the length of the text you want to always be present). That might work
I also first thought of this, but suppose if user appended some text then its lenght got increased, now he acts smart and jumps back , then he can delete as length is greater(as he adds some text)
Application is on order progress.
Where user has to update its order action/remarks?
I am fetching text from DB to textControl, and user have to update these fields.
So if user once entered some data and updated it, then next time he can only append new data, can't modify previous data.
Any help appreciated....?
|
|
|
|
|
I knew it would have a flaw somewhere lol
what about on KeyPreview do some check using the caret position of the text box?
So keep the backspace/delete check and also add - if caret < fixed length then don't allow key press to go through
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
an example would be greatful.
or else i have to run hit and try method on my own
|
|
|
|
|
Perhaps if you build on musefan's idea but use the Tag property to store the length of the Text when the TextBox has been initialized (i.e. the "uneditable" text has been assigned to it)..? Then you always know the initial length and you can prevent it from being modified.
However, I think a better solution would be to split the UI to reflect that there's a read-only part and the user may add to this. This would make it easier to implement, and imho more logical for the end user as well.
If you do opt for a single TextBox control you may have to handle cut/copy/paste (if you select text and paste, you replace the selection) as well.
|
|
|
|
|
Hum Dum wrote: How to do this?
Manually.
See TextBox.OnChange event, but be aware that this is "odd" behaviour - not what users expect from a text box. Is there no better solution you can apply, such as moving the text to a label so the TextBox is empty?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
OriginalGriff wrote: moving the text to a label so the TextBox is empty?
This is one solution?
But moving whole text to a label then adding new text?
application like daily/weekly update on a task.
so text is goes on increasing?
also there are 3-4 fields where user has to add its progress,
and moving each on a seprate labe, makes things somewhat unpleasent?
can't there be any better way.....?
just user can't modify previous data?
any help appreciated....
|
|
|
|
|
Hum Dum wrote: But moving whole text to a label then adding new text?
application like daily/weekly update on a task.
so text is goes on increasing?
also there are 3-4 fields where user has to add its progress,
and moving each on a seprate labe, makes things somewhat unpleasent?
can't there be any better way.....?
just user can't modify previous data?
any help appreciated....
Ok, so what it is is an update of a to-do-list or similar, with the user inputing new progress?
In which case, yes it will keep increasing - what you need to do is treat each new progress update as a new record and display it in - for example - a grid control. Or better a DataGrid if you store the updates in a database, which would make sense.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Try this in TextBox Keypress event
if(textbox1.text.lenght > 0)
{
if(e.KeyChar == "backspace","Delete","shift","Home","End"
{
e.Handled = true;
}
}
|
|
|
|