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

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

Problem with JavaScript on Textbox

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
 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?  

View Complete Post

More Related Resource Links

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){ } }

What's the problem in my javascript's code to get ClientID Property?



 Hi all.

I wirte a simple java script code to get ClientID of controls on the webform. The code is like:

<script type="text/javascript" language="javascript">

var butt = $find("<%= Button1.ClientID %>");



But when i run it , i have a problem. The probmel is:


Server Error in '/' Application.

The Controls collection cannot be modified because t

Problem in getting contol id in JavaScript


Hi want to get the Control ID in a javascrip so that i assign some value in it. 

document.getElementById('<%=hiddenSplitterCollapsedState.ClientID%>').value = mode

but on running .aspx page it's giving an Error

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


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

collapsiblepanel problem with javascript

Hiiii Coders, I have 4 collapsible panels on my page. Now i am using below javascript code for expanding and collapsing all the panels at the same time.  <script type="text/javascript"> function TogglePanels() { var panels = ["cpe1", "cpe2", "cpe3", "cpe4"]; for (var i = 0; i < panels.length; i++) $find(panels[i])._toggle(); } </script>here is my code for linkbutton (collapse all/expand all) and collapsiblepanel extenders<tr> <td align="right" valign="top"> <p style="text-align:right;"> <asp:LinkButton ID="L1" runat="server" Text="expand all" OnClientClick="TogglePanels();this.innerText=this.innerText=='expand all'?'collapse all':'expand all'; return false;"> </asp:LinkButton> </p> </td> </tr> <tr> <td> <cc1:CollapsiblePanelExtender ID="cpe1" runat="Server" TargetControlID="Panel1" ExpandControlID="Panel2" CollapseControlID="Panel2" BehaviorID="cpe1"

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

linebreak in textbox using javascript

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?

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>

Problem with overriding OnPaint method of System.Windows.Forms.Textbox

Hi,   I want to change the border colour of the Textbox. However, when I override the OnPaint method, some strange behaviour occurs.   The new border is drawn, as is the textbox background. However, the text itself appears in bold and only while I actually type something in, afterwards it disappears. I have provided a sample of my code here:         protected override void OnPaint(PaintEventArgs e)         {             base.OnPaint(e);             Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);             ControlPaint.DrawBorder(e.Graphics, rect, _BorderColour, ButtonBorderStyle.Solid);         }   I have also set the style of the control to Userpaint, so that the paint method is actually used. Does anybody know how to solve this issue?

problem with changing cssclass name using javascript

function DoFocus(fld) { fld.className = 'textboxFocus'; } function ChangeToFocus() { document.getElementById('<%=tbComment.ClientID%>').className="textboxFocus"; } button1.Attributes.Add("OnClick", "ChangeToFocus();")//Not working tbComment.Attributes.Add("OnFocus", "DoFocus(this);")//Working I have two methods to change a control's css class (etc. textbox), however, javascript method 'ChangeToFocus' is not working but I do need that function or something could do the samething (I can't use DoFocus(fld) function as it need to pass that control's reference)     Many thanks for your help! Ray

javascript and c# problem

Hi all, Please help me with this issue, very urgent... Many thanks in advance.. I have a web form where I call a method, if page is not post back some thing like if (!IsPostBack)        FillCustomerDetails(); and FillCustomerDetails call a third party component and get a string back. I chop that string fill few asp:TextBox like  txtAddress.Text = obj.Address; txtPostCode.Text = obj.PostCode; etc... Now I have a  <input type="text" name="getAddress" id="getAddresst" onkeyup="keyUp(event)" /> control on the same page. So when user type in any thing in this Textbox, onkeyup is fired which is written in seperate .js file, which I have included on this page. Now this javascript Function onkeyup calls the c# code as document.getElementById('btnAddress').click(); (which is a <asp:Button>) So javascript is basically calling c# code and c# code is setting the values on <asp:TextBoxex> like  txtAddress.Text = obj.Address; txtPostCode.Text = obj.PostCode; Now my problem is, first time when page is loaded , it checks !IsPostBack and fills the TextBoxes txtAddress.Text = obj.Address; txtPostCode.Text = obj.PostCode; But when user types the new Address in the <input type="text" name="getAddress" id="getAddresst" onkeyup="

javascript onclick problem

I have 3textboxs namely txt1, txt2 and txt3. If  txt1 and txt2 not null, sum is calculated in txt3 when OnClick. Now the problem is that when OnClick to txt3,by default the  cursor is blink on left but I want to set on right. Eg, OnClick to txt3 it show 3251, and then the cursor is blink just befor the 3 but i want to blick after 1. Help me plz! Regards, Bedajit  

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.

deserialize json string using javascript serializer problem



A json string was sent from client side to asmx web service.

Here json string is as below

"Name":"Ablation of Aflutter","BillingCode":"93651","ServiceCode":"1062","Value":1},
"Name":"Ablation of Atrial tachy","BillingCode":"93651","ServiceCode":"1062","Value":1},
"Name":"Ablation of AVN for CHB w/ or w/o temp pacer","BillingCode":"93650","ServiceCode":"1061","Value":1},
"Name":"Ablation of VT","BillingCode":"93652","ServiceCode":"1063","Value&q

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?




Problem Creating Server Side Javascript


I have a custom control which creates client side Javascript in order for it to function. When the property .OnSelectScript is wrapped in an if...then that tests its length, the value of .OnSelectScript appears to be ignored when the Javascript is being generated. However, when I set the .text value of a test label to Javascript, it appears there. I have confirmed that the statement *does not* appear client side when I view the source for the page.

Property declaration for the control

    Public Property OnSelectScript() As String
            Return _OnSelectScript
        End Get
        Set(ByVal value As String)
            _OnSelectScript = value
        End Set
    End Property
    Private _OnSelectScript As String

Full SUB as designed

    Protected Sub Page_Load() Handles Me.Load

        Dim ClientSideJavaScript As New StringBuilder

        LabelSelectorTitle.Text = Me.Title
        Call LoadData()

        ClientSideJavaScript.Append("/*File: Test Selector.aspx.vb Sub: Page_Load()*/" & Chr(10))
        ClientSideJavaScript.Append("function setValue(ParentPopup, TargetDisplayControl, NewDisplayValue, TargetTextboxControl, NewKeyValue) {" & Chr(10))

textbox focus problem


I have a textbox (txtMaiden) and a radio button list (rblGender) in two separate User Controls that I'm using for a registration site. The txtMaiden control appears or disappears depending on whether Male or Female is designated on the radio button. This all works fine but I want the textbox to have focus when it becomes visible. As of now, it only gets focus when the page refreshes. Code follows. Any ideas?

<Prf:gender ID="GenderE" Gender='<%#Bind("Gender")%>' runat="server" />
<Prf:maiden ID="MaidenE" Maiden='<%#Bind("MaidenName")%>' Maiden_Disp='<%#Bind("MaidenName_Disp")%>'
    runat="server" />

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="gender.ascx.vb" Inherits="userControls_profile_gender" %>
<asp:Panel ID="pnlGender" Visible="true" runat="server">
    <div class="label">
        <asp:Label ID="lblGender" Text="Sex:" runat="server" />
    <div class="ctrl">
                <asp:RadioButtonList ID="rblGender" AppendDataBoundItems="True" AutoPostBack="True"
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