.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

linebreak in textbox using javascript

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :ASP.Net
I want to assign a textvalue with linebreaks to a textbox control using javascript.I tried (\n):hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}\n\n\n#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")and tried (<br/>)hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}<br/><br/><br/><br/>#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")But without luck....How to do it?

View Complete Post

More Related Resource Links

Issues with multiline textbox, javascript and IE


Hi All,

i have a requirement to embolden/italicise the selected  text in a textbox. the way it is implemented as is by using a js function which inserts <b> and </b> tags at the start and end of the selected text  for bold, and similarly <i> and </i> tags at the start and end of the selected text  for italics.

here is the code in c# (to add attributes to link buttons)

lkbBold.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'B'); return false;");
lkbItalic.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'I'); return false;");

the txtTitle is the id of the text box, which contains the selected text to be emboldend.

and here's the javascript method

function AddHTMLTags(textBoxId, format)
  var textComponent = document.getElementById(textBoxId);
  var selectedText;
  var textToReplace; 
  var content = document.getElementById(textBoxId).value;
  var content1 ;
  var content2 ;
  var newContent; 
      // For IE 
      if (document.selection != undefined)
        var len =  document.selection.createRange().text.length;
        var myrange

Javascript to update value in Textbox

Hi I have a javascript file, which creates a calendar picker. This file is used through out the application and is a piece of code that I have to use because my .Net application is part of another application which uses this piece of JavaScript code.Anyhow, with the calendar picker I can save the date into a textbox, but the problem that I have is the format. Unfortunately, I cannot change the calendar picker code because this will affect other parts of the application. Therefore, what I am looking to do is to reformat the date on the textbox control. This I can do but only when I use the javascript event onfocus.Now, my question is this, is there away in javascript or with jquery that when a value enters into a textbox that this value is then reformatted to the format I want without postback or clicking on the textbox?Thanks

Problem with JavaScript on Textbox

 I have a textbox which is populated by an external javascript file which I cannot alter without affecting another part of the system. What I would like to do is once this textbox has a value to do something with it. The javascript that I want to use is fine, but it won't automatically when a value has populated it i.e. onchange. It will work when the event is onfocus. Is there away in which I can automatically fire off my javascript event when a value has entered the textbox from another piece of javascript code?  

problem with javascript in multiline textbox

 I am setting Maxlength of a textbox using javascript. Take maxlegth as 100.As we know Enter key is taking two char space. But i want to avoid this. i.e. if i press enter key after 96th char it should allow me to enter four more char where now it is allowing only 98. This is wat i am using  function textboxMultilineMaxNumber(txt,maxLen) { try { if(txt.value.length > (maxLen-1)) return false; } } catch(e){ } }

javascript for field validation on a textbox...

I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

Not able to bind textbox with javascript textbox? Why?

I'm trying to use a javascript Date and Time calendar in my Insert and Edit templates in a Detailsview that is bound to SQL Fields. The reason I am trying the javascript date time selector is that I need to have the date and time, the asp.net one is just the date part. I guess my first question is this possible? I tried using it with an asp:textbox on just a plain aspx page and it works like a charm, however when I add it to the detailsview i keep on getting the "Error: Object required"  am I missing a step here?  That and seeing as I'm using a site master page where exactly do I put the:  "<script type="text/javascript" src="datetimepicker_css.js"></script> "   <asp:TemplateField HeaderText="Start Time" SortExpression="StartTS"> <EditItemTemplate>   <asp:TextBox ID="STEditCalendartxt" runat="server" Text='<%# Bind("StartTS") %>'>    </asp:TextBox> <a href="javascript:NewCssCal('STEditCalendartxt','mmddyyyy','arrow',true)"> <img src="images/cal.gif" width="16" height="16" alt="Pick a date"></a>  </EditItemTemplate> Any assistance would be greatly welcomed.

Disable copy paste in textbox without Javascript




Can you somebody help me in disabling copy paste in the textbox without using Javascript for an web application?




How do you get a textbox/input or a javascript to postback?


I am using a Yahoo UI dual slider.  The dual slider changes values based on what you slide.  It uses javascript and sends this value back to a Input type="text" textbox. 

I want to be able to do a automatic postback and call the server function "protected void zoom(object sender, EventArgs e)"  each time the slider value changes.

So what I did was:

<asp:TextBox type="text" id="demo_from"  runat="server"
OnTextChanged="Zoom" AutoPostBack="true">

But the problem is, it WILL not fire the server-side event unless I manually click the textbox and press "ENTER".  Then the event will fire (during debug).

So how can I get the event to auto-fire each time the slider value changes?


Adding Textbox values using javascript.


Hi All,

i am developing an application using ASP.NET with C#.

in my application i have 4 textboxes. they are 1. Textbox1




Is it possible to get TextBox properties in javascript



Is it possible to get TextBox properties using javascript 

width, height.. like as

 If anybody have idea please let me know ..

thanks in advance




Setting value of asp:textbox in Javascript in ASP.net 3.5


I created a page with several controls (ddl, tbx) that I use for filtering a Gridview.  I created a javascript function that runs on the OnClientClick Event of an <asp:button  to set the value of an <asp:TextBox to today and a Selected Value in a ddl. 

function setMyToday() {
            var tbxToday = document.getElementById('ctl00_cntPage_tbxToday');
            var tbxUID = document.getElementById('ctl00_cntPage_tbxUserID');
            var ddlPV = document.getElementById('ctl00_cntPage_ddlProvider');
            tbxToday.value = makeToday();
            ddlPV.value = tbxUID.value;

The button submits the page and returns some records in a Gridview.  I can see the value in the tbxToday when the button is clicked and the row in the drop down list, but when the page is posted,the value in the text bos is lost and as a result is not used to filter the records.  However the value in the ddlProvider is

How can you use javascript to call a SliderExtender (textbox) to update its value?


I am trying to develop two step size buttons + and -  so that when you click either one, the AJAX SliderExtender will magically move itself by one.

I have tried implementing the following functions:

document.getElementById ("Slider1_BoundControl").value = 5;
document.getElementById ("Slider1").value =5;

here's what happens, I see that the BoundControl textbox works and it gets updated to 5.  However, the slider still does not update to its new position.  When the slider moves, a postback will occur.

The Slider1 is the textbox that  is the targetID to SliderExtender1 .  The boundcontrolID is Slider1_BoundControl (textbox)

Anyone know ? thanks

How do you use javascript to modify asp:textbox attributes? (set autopostback)


If you have this item in the aspx page:

<asp:TextBox ID="Slider1" runat="server" OnTextChanged="Slider1_TextChanged" AutoPostBack="True"  >

how do you write a javascript function to set AutoPostBack="False" and to OnTextChanged to something else?

any examples please? please show me with some code.


JavaScript Compare BoundField and TextBox in a GridView


Hi everyone. 
Below I have a BoundField and a TextBox.
When the user moves away from the TextBox, I need to compare the BoundField (minQty) and the TextBox (Qty).
How do I pass the values of the BoundField and TextBox to a Javascript eg. CheckMinQty(Qty,minQty) when the user moves away from the TextBox?

javascript textbox clear not working



i have javascript to clear the textbox but its not working and js called asshipping.js

below the code i have in asshipping

function clear() {
function clearfields() {
    O('TextBox1').value = '';
    O("TextBox2").value = '';
    O('TextBox3').value = '';

function O(id)
  return document.getElementById(id);

default.aspx page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>

   <script src="Script1/asshipping.js" type="text/javascript"></script>
<body  >
    <form id="form1" runat="server"  >

        <asp:Button ID="Button1" runat=&q

find textbox control of gridview using javascript



 I am inserting a data in gridview row. I have 2 textbox's, 1 label and 1 textbox respectively. Here, I want to do calculations on data which is in first two textboxes and result should be displayed in label and the text in label to be multiplied with 40 and that should be displayed in last textbox.

 This operation to be done in onblur() event of second textbox. To do this I need to find the controls in gridview in onblur() event of the textbox.

  I tried to do this in .cs file but this operation is to be done before inserting in to database on that particular row of gridview.

I searched on the net but i couldn't find the solution. I couldn't know how to find textbox of a gridview using javascript

Please help me.....

Round Gridview footer template textbox value based on this JavaScript



This is my aspx javascript to get total in gridview footer template.. its working fine

The problem is : some time it show footer value is 6.9999999999

I need 6.99 as a result how to achieve this.

Aspx page:-

<script type="text/JavaScript">
function updateControls(elementId)
 var parentElementRef = document.getElementById(elementId);
 var elementRefArray = parentElementRef.getElementsByTagName('INPUT');
 var textBoxTotals = 0;

 for (var i=0; i<elementRefArray.length; i++)
  var elementRef = elementRefArray[i];

  if ( (elementRef.type == 'text') && (elementRef.gridTextBoxType == 'calcTextBox') )
   var textBoxAmount = parseFloat(elementRef.value);
   if ( isNaN(textBoxAmount) == true )
    textBoxAmount = 0;

   textBoxTotals += textBoxAmount;

 if ( isNaN(textBoxTotals) == true ) 
  textBoxTotals = 0;

 for (var i=0; i<elementRefArray.length; i++)
  var elementRef = elementRefArray[i];

  if ( (elementRef.type == 'text') && (elementRef.gridTextBoxType == 'totalsTextBox') )
   elementRef.value = textBoxTotals;
// -->


protected void Gridview1_RowDataBound(object sender, Grid
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend