.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

Problem in getting contol id in JavaScript

Posted By:      Posted Date: August 26, 2010    Points: 0   Category :ASP.Net

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:


View Complete Post

More Related Resource Links

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

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"

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

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  

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

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

problem in passing string array from activex dll to JavaScript


I do have a problem in passing string array from activex dll to JavaScript. i need to implement a methos as 

C# : 

Asp.Net Routing Css And Javascript Reference Problem


Hi All!

I have problem with url routing. I'm using Asp.Net theme in my project. My theme is messing up. I couldn't figure out how could i ignore the css and js files.

Web.Config theme reference;

<pages theme="Default" styleSheetTheme="Default" ></pages>

I've tried;


routes.RouteExistingFiles = false;//assume routes as my routecollection

and this;

            routes.Ignore("{*alljs}", new { alljs= @".*\.js(/.*)?" });
            routes.Ignore("{*allcss}", new { allcss= @".*\.css(/.*)?" });

and this;


but still doesn't work. Some of my friends told me to use ResolveClientUrl but i can't figure out how to reference it(because asp.net theme writes it for me already).

I need help. Thanks.

p.s sorry for my bad english

prevent postback javascript problem


i have the following example but i get error on GetPostBackEventReference line

value of tpe ...button cannot be converted to....

second question:where should i put this code? do i need just this code and nothing else

how should i for example delay for 20 seconds??

Dim sb As New System.Text.StringBuilder()
            sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
            sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
            sb.Append("this.value = 'Please wait...';")
            sb.Append("this.disabled = true;")
            Me.btnAddPhotoComment.Attributes.Add("onclick", sb.ToString())



Javascript Regular Expression Problem


Hi all,

I have the problem about using regular expression.

At first, I found currency textbox script at http://blog.developers.ie/cgreen/archive/2009/04/24/currency-field-with-javascript.aspx.

Thank you Mr. Christopher Green for first solution. Smile

It is very cool script for inputable only decimal number.


After that, I had more requirement about "currency textbox can inputable '-' sign".

Ex. It can inputable '-23.89'.

I try apply regular expression in below function

function fnCurrencyOnly(o) {
            var sValue = o.value;
            var sKey = String.fromCharCode(window.event.keyCode);
            if (document.selection.createRange().text == sValue) {
                sValue = sKey;
            } else {

asp:HyperLink javascript problem


I have a asp:HyperLink control in my page. I need to change both the ImageUrl and NavigateUrl fields of the hyperlink in client side based on the selection made in the dropdown.

I have a collection from which I can get the value for ImageUrl and NavigateUrl. Only problem I'm having is what is the code to set these values from javascript?

First I tried:

var hl = document.getElementById('<%= hlImage.ClientID %>');
hl.src = arrImage[0];

but I get error on it, so I changed it to

hl.lastChild.src = arrImage[0];

which also gave me an error. I need to change both values from javascript.


Problem with a Javascript Popup Window Minimizing itself


I am new to Javascript.  I have seen other posts about this, but I have not been able to resolve my problem. I have a WebPage that allows a user to click a LinkButton. When the LinkButton is clicked. I execute the following Javascript code after registering the ClientScriptBlock:

<script language='Javascript'>
PopupWindow = window.open('StandardImageLookupPage.aspx','PopupWindow');
PopupWindow.resizeTo(screen.width, screen.height);

No matter what I do the popup window comes up for a brief second and then minimizes itself. I prefer that the window stays maximized.

I am stumped. Any help would be much appreciated.

ps. I am not sure if this makes a difference, but the WebForm that calls this javascript is a user control.

problem with user control+update panel+javascript


hai all,


Im having a aspx page which has 5 tabs inside a update panel..also I have a user control

Wen I click each tab im dynamically loading dat user control .

The problem is im using javascript in dat user control..

the user control has a button which displays a panel containing three grid views  n s activated by a java script as given below..

function Elig()



'<%=btnLegend.ClientID %>')).click(function(){


('<%=pBody.ClientID %>')).slideToggle('slow');




Wen i run the aspx page the first tab  successfully loaded with dat user control n a

Problem binding a collection to a view model on POST when manipulating the DOM with javascript.


Hi, i'm currently working on a strongly typed view and i'm binding a collection to a table like this:


for (int i = 0; i < Model.Cars.Count; i++)





<%= Html.Hidden(String.Format("Cars[{0}].Id", i),




<%= HtmlTextBox(String.Format("Cars[{0}].CarModel", i),



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