I have a textbox as follows:
<asp:TextBox runat="server" ID="txtOtherApps" Height="400" Width="400"
TextMode="MultiLine" ontextchanged="txtOtherApps_TextChanged" ></asp:TextBox>
How to display link in this textbox?
The TextBox allows you to display text which the user can edit. It does not allow you to display anything but plain text. To display a URL in the TextBox, simply set its Text property:
txtOtherApps.Text = "http://www.example.com/";
It wont, however, be a "link". Clicking the URL will cause a text cursor to be placed, allowing for the user to edit the URL.
It is possible if you use JavaScript
Use JavaScript on your text element - such that:
<input type="text" name="t1" id="t1" value="http://www.google.com" onmouseover="this.style.cursor='pointer' ;" onClick="window.open(this.value);"/>
Only Java script can do what you are asking for.
You won't be able to click on the link, but you can just set the Text property of the TextBox to the URL.
ASP.NET will render TextBoxes as textareas (in your case, because it's multiline) or inputs. These are standard HTML fragments which are just plain text containers. You can style them, but you can't really linkify the contents of them.
If you really just want to put the text of a link into a box, do this:
// either from the server:
txtOtherApps.Text = YourLinkString;
// or from the client:
<script>
document.getElementById('<%=txtOtherApps.ClientID%>').value = YourJsLinkValue;
</script>
If you want something to happen with the user clicks on the text area, you can add an onclick handler to it...but this would be weird.
You will need a RichTextBox. The .NET one is not available for web applications, but there are a few third party solutions available.
http://www.richtextbox.com/ is one of them, you will have to see for yourself if there is any available that suits your needs better.
Related
I have a panel that gets a hyperlink added dynamiclly through C# with values from an sql database.
However some of the URLs are really long and quite uneccessary to display.
I have not found any good ways to hide/disable the url showing and replace it with text. I can not use normal <a href> as it handled server side.
EDIT added some of the code.
<asp:HyperLink ID="moduleHyperlink" runat="server"></asp:HyperLink>
now in C#
HyperLink hyp = createHyperlink(btn.link);
moduleHyperlink.Controls.Add(hyp);
This will display for the user the entire btn.link (url string) which might be really long and it looks messy on the webpage. I would rather have a text saying "External Link", which when clicked redirects the user to the url.
You can add Text property to show some valid link title instead of showing the URL.
HyperLink hyp = createHyperlink(btn.link);
hyp.Text = "YourTextForTheLink";
moduleHyperlink.Controls.Add(hyp);`
net page with two controls
linkbutton
button
While running my application, I'm changing my link button text using javascript function.
Now I want to read that text when I press button. Button event is there in server side.
When I try to read like below
string s = linkButton.Text;
It is not giving my updated text.
How can I get it?
At first, declare this HiddenField in your markup
<asp:HiddenField ID="link" runat="server" />
Then in the function, you change the link button text, you should add the following code, in order the new text to the HiddenField been added.
document.getElementById(<%=link.ClientID%>).setAttribute("Value",newText);
Last, in your server side code you can get the value you want with the following way:
string s = link.Value;
You can use a HiddenField.
The LinkButton does not implement IPostBackDataHandler, therefore it doesn't load postback data.
You can write the HiddenField.Value on client- and read it on serverside.
Here's a tutorial-video: [How Do I:] Use a Hidden Field to Store and Manipulate Client-Side Information
I am using <asp:TextBox> not HTML textbox and I want to display hint text.
Is there any way to achieve that?
I have tried for making static text and color it gray but not getting how to make it empty when cursor get focus to that textbox.
<asp:TextBox ID="TextBox1" runat="server" placeholder="Hint Text"></asp:TextBox>
Use a ASP.NET WaterMark TextBox
It is in Ajax Toolkit
You, can give in Code behind like follows
textBox.Attributes.Add(“onfocus”, “clearText(this,’” + defaultText + “‘)”);
And also refer to this to know more.
You can using "placeholder" properties for textbox.
Example
<asp:TextBox ID="TextBox1" runat="server" Width="233px" placeholder="Search"></asp:TextBox>
You could use the HTML5 placeholder attribute for that. The downside is that it's only supported by some browsers. Fortunately you have JQuery Placeholder to the rescue. This plugin makes the placeholder behavior available for unsupported browsers.
Check it out here JQuery Placeholder
text input watermarks using javascript.
refer this it might help u
http://naspinski.net/post/Text-Input-Watermarks-using-Javascript-%28IE-Compatible%29.aspx
just add property placeholder="HintText" in your asp textbox
I am working on a simple web forms application with C# (Microsoft Visual C# 2010 Express).
I have two text boxes (textBox1, richTextBox1) a button (button1) and a web browser (webBrowser1) on the form. The web browser goes to a web page when I run the program. On that page there are two input fields that I want to autofill with the click of the button1 using the text in textBox1 and richTextBox1.
You can see the code of the input fields on that web page:
<input type="text" id="subject" tabindex="4" name="subject" value="">
<textarea class="composebody" tabindex="6" name="message" id="message" rows="20" cols="80"></textarea>
I know this is very simple, but I don't have much knowledge about C#. Any ideas how I can code that?
Thanks.
You need to write this code
webBrowser1.Document.GetElementById("subject").SetAttribute("value", subject.text);
webBrowser1.Document.GetElementById("msg").SetAttribute("value",message.text );
and need to call those two lines in
DocumentCompleted event of webbrowser.
Hope it helps.
I believe you are looking for the following:
subject.value = "Your info here";
This will solve the issue for your first item but the text area is a bit more tricky. You will probably need to include some HTML item inside the text area that you can write to. I was not able to find a good way to write to the textarea item easily. If possible, I would suggest using a different control.
I want to develop an application in asp.net with C#.
In that application there are one text box and one label.
I want the following functionality:
When I press any key in textbox then I should get this value on .cs page i.e; code behind. And from .cs page I want to add this value to the label.
The problem is that there is no keypress event for an asp textbox and if I take a html text box then I don't get its value on .cs page
How can I come out with this problem?
Because a keypress on a textbox is a client side event but you want to perform server-side processing you will need to use AJAX requests.
You may find the following useful:
AJAX Toolit
Using Jquery to call asp.net page methods
In asp.net the TextBox will have TextChanged event but you will need to enable post back for the button and the event will fire when you tab out of the TextBox.
For the task you want either use javascript or add a button and when this button is do what you want.
I don't think this is a good aproach in web app., In this way you will end with a lot of post-backs.
However, if you still want this functionality. Texbox has TextChanges event, and if you also change the textboxs's AutoPostBack property to true you will get something close, but you will still have to move a currsor.
But it is still a terible solution. Why don't you simply use a button that fires click event instead?
Alternative solution is to use Ajax or javaScript,..
You can simply create a JavaScript-Method for this.
Your Textbox:
<asp:TextBox ID="textBox" runat="server" onkeydown="onFilterTextChanged()">
</asp:TextBox>
Your JavaScript, do a TimeOut to not do this every 0,0001 secs.
function onFilterTextChanged() {
if (timeoutID)
window.clearTimeout(timeoutID);
timeoutID = window.setTimeout(updateFilterText, 600);
}
Send the Values to the CodeBehind, textis your TextBox-Text.
function updateFilterText() {
var text = document.getElementById("<%=textBox.ClientID %>").value;
__doPostBack("<%=textBox.ClientID%>", "CommandArg" + text);
}
You won't need to do as many PostBacks as with the native TextChanged-Event and you can simply use this e.g. for Auto-Extender-Plugins. Pack the TextBox into an UpdatePanel and you're good to go!
Unless of course you do not NEED to go back to the server, in which case just set the labeltext in updateFilterText.