javascript working on my machine (application server), but not on client.

I am making a div container visible or hidden based on user selection using javascript and css.

like a javascript function is -

function funHide()

{

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value','  ');

}

and css is -

/*For making a control block hidden.*/

.CntrlHidden

{visibility:hidden;display:none;}

/*For making a control block visible.*/

.CntrlVisible

{visibility:visible;display:block;}

Javascript is  working perfectly fine once i am accessing site on my machine(which is also development as well as testing server), using IIS.

but on client machines browser, it is not working.

please help.

0
varun5318
3/24/2009 12:24:29 PM
asp.net.client-side 24353 articles. 1 followers. Follow

28 Replies
528 Views

Similar Articles

[PageSpeed] 12

hi Varun,

Check if javascript is disabled in the client machine or not.


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
3/24/2009 12:33:14 PM

Have you check is javascript enabled in the client browser


Thanks
Hari
---------------------------------------------
Dont forget to click "Mark as Answer" on the post that helped you.

My Site
0
hariram
3/24/2009 12:34:06 PM

Yes JavaScript is enabled in client browsers.

A similar code, is working in an older application; that we had developed using VS2005.

Now I am working with VS2008.

Though its should not be the case with VS2008.

But the thing making me disturb, that I am accessing the page using IIS, and then its working on my machine only.

0
varun5318
3/25/2009 5:19:44 AM

Is the javascript kept in a separate javascript file. If show make sure given proper relative path in <link href=~/Includes/Scripts.js runat='Server' Make sure lamda symbol and run at server in ref link

 


Thanks
Hari
---------------------------------------------
Dont forget to click "Mark as Answer" on the post that helped you.

My Site
0
hariram
3/25/2009 5:24:21 AM

 Hi..

please also check  that id you are using in document.getElementById, client browser generating same id in HTML. pls check in viewsource

or better using obj.ClientID in  document.getElementById

ex: document.getElementById('<%=obj.ClientID%>');


||- Paresh -||
[GTL-Ahmedabad]
0
paaresh
3/25/2009 5:34:34 AM
varun5318:
function funHide()

{

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value','  ');

}

try this instead

function funHide()

{

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

document.getElementById("<%=TxtDrawnOn.ClientID%>").setAttribute('value','  ');

}


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
3/25/2009 5:49:51 AM

function funHide()

{

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value','  ');

}

what typeof control is PayMode, you need to get its correct ClientID from server?

replace the second line with this

document.getElementById('<%ContentPlaceHolder1.FindControl("TxtDrawnOn").ClientID %>').setAttribute('value','  ');


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/25/2009 6:04:50 AM
Here the PayMode is a div tag, in which exist a set of server controls. which i want to make visible or hide based on user selection.


I have tried both the syntax-


document.getElementById('').setAttribute('value','  ');

document.getElementById("').setAttribute('value','');


But now its throwing JavaScript error, saying that.

document.getElementById(...) is null or not an object.

pls help.
0
varun5318
3/25/2009 8:51:53 AM

1. Make sure that PayMode id is there when you do the view source of the page. because i doubt that is is

ctl00_ContentPlaceHolder1_PayMode

2.  if a div with paymode id  is there , then , replace

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

with

document.getElementById('PayMode').className ="CntrlHidden" ;

 

3. where are you getting the error,

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

or

 document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value','  ');

 

 debug this way,

function funHide()

{

try

 

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value','  ');

}

catch(e)

{

alert(e.message);

return false;

}

 }


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/25/2009 9:05:38 AM

varun5318:

I am making a div container visible or hidden based on user selection using javascript and css.

like a javascript function is -

function funHide()

{

document.getElementById('PayMode').setAttribute('class','CntrlHidden');

document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value','  ');

}

and css is -

/*For making a control block hidden.*/

.CntrlHidden

{visibility:hidden;display:none;}

/*For making a control block visible.*/

.CntrlVisible

{visibility:visible;display:block;}

Javascript is  working perfectly fine once i am accessing site on my machine(which is also development as well as testing server), using IIS.

but on client machines browser, it is not working.

please help.

Shouldn't it be .setAttribute('className', 'CntrlHidden')

NC...

0
NC01
3/25/2009 11:38:07 AM

 

NC01:
Shouldn't it be .setAttribute('className', 'CntrlHidden')

i don't think it should be, className is javascript property which internally produces this class attribute , and the same is being done here through setAttribute.

<div class="myclass"></div>


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/25/2009 11:54:22 AM

shashankgwl:

 

NC01:
Shouldn't it be .setAttribute('className', 'CntrlHidden')

i don't think it should be, className is javascript property which internally produces this class attribute , and the same is being done here through setAttribute.

<div class="myclass"></div>

If you look at the post, he IS using JavaScript to set the attribute. The markup is translated into the JavaScript property name.

NC...

 

0
NC01
3/25/2009 12:01:40 PM

you mean to say, when he writes

div.setAttribute('className','myclass'), this will be produced

<div class="myclass" />

OR THIS WILL BE PRODUCED

<div className="myclass" />

 


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/25/2009 12:11:04 PM

This will be produced: <div class="myclass" />

I don't use setAttribute myself, so I don't know for sure, but it should work the same as elementRef.className = 'myclass'

NC...

0
NC01
3/25/2009 12:34:08 PM

NC01:

This will be produced: <div class="myclass" />

I don't use setAttribute myself, so I don't know for sure, but it should work the same as elementRef.className = 'myclass'

NC...

 

hmm, but i use it a lot, and sorry but this (<div class="myclass" />) will not be produced Smile


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/25/2009 2:37:34 PM

Thanks a lot to all of you.

The problem got solved using the following syntax.

function funHide()

{

document.getElementById('PayMode').className = "CntrlHidden";

document.getElementById('ctl00_ContentPlaceHolder1_TxtDrawnOn').setAttribute('value',' ');

}

So here i can say some findings as below -

1- document.getElementById('PayMode').setAttribute('class','CntrlHidden');

is working only on my machine, even I though i am accessing it through IIS.

2- document.getElementById("<%=TxtDrawnOn.ClientID%>").setAttribute('value',' ');

is not working at all, Using it giving JavaScript error saying that document.getElementById(...) is null or not an object. Though therotically it should work.

3- document.getElementById('PayMode').setAttribute('className','CntrlHidden'); is not going to work at all.

If any body can tell me what is the problem in afforsaid 2nd case, i would be thankfull. As I have to use

'ctl00_ContentPlaceHolder1_TxtAccNo', full rendered name, which should not be the case.

0
varun5318
3/26/2009 7:16:36 AM

plz do this

do the view source and check two things

1. what is the corresponding HTML of  document.getElementById("<%=TxtDrawnOn.ClientID%>").setAttribute('value',' '); coming on the browser.

 

2.  what is the client id of TxtDrawnOn  coming on the brwoser.

 


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/26/2009 8:07:57 AM

Actually I am having seprate JavaScript and CSS files.

So how can i know what document.getElementById("<%=TxtDrawnOn.ClientID%>") is rendering to?

and TxtDrawnOn is rendering as ctl00_ContentPlaceHolder1_TxtDrawnOn.

 

0
varun5318
3/26/2009 10:25:18 AM

Hi Varun, 

varun5318:

So how can i know what document.getElementById("<%=TxtDrawnOn.ClientID%>") is rendering to?

and TxtDrawnOn is rendering as ctl00_ContentPlaceHolder1_TxtDrawnOn.

 

When you use TxtDrawnOn.ClientID ,actually after rendering it will take the value ctl00_ContentPlaceHolder1_TxtDrawnOn only.

So both are same. You can use anyone amongst them like document.getElementById("ctl00_ContentPlaceHolder1_TxtDrawnOn")...but

the first choice is recommended.


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
3/26/2009 10:33:04 AM

Yep I know both will the same thing. But therotically the syntax of document.getElementById("<%=element.ClientID%>") must work which is not working, in my case.

 

0
varun5318
3/26/2009 11:33:17 AM

hi varun,

Could you plz let us know how the code is not working.

is is showing a javascript error or what?

What it is showing if you use  alert(document.getElementById('<%= YourServerControl.ClientID %>'));

The output should be object.

 


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
3/26/2009 11:48:41 AM

Joy,

using  alert(document.getElementById('<%= YourServerControl.ClientID %>')); is returning null to me. I myself think it should return object but thats not happening.

 

0
varun5318
3/26/2009 12:06:50 PM

varun,

Put your javascript code like below,

 onload=function()
     {

 alert(document.getElementById('<%= YourServerControl.ClientID %>'));

}

Let me know the status


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
3/26/2009 12:12:06 PM

Joy,

Actually I am working with MasterPage, so i have created a seprate funciton as -

function funTest()

{alert(document.getElementById("<%=TxtDrawnOn.ClientID%>"));}

and called it onclick="funTest()" of div element. It is returning null.

 

 

0
varun5318
3/26/2009 12:30:24 PM

varun5318:

Yep I know both will the same thing. But therotically the syntax of document.getElementById("<%=element.ClientID%>") must work which is not working, in my case.

 

That won't work if you are using included JavaScript files. In other words, that will ONLY work if the JavaScript is actually and physically inside of the markup.

NC...

 

0
NC01
3/26/2009 12:39:56 PM

Hi Varun,

I think that it is showing null because when you are calling that method that time that control has not been rendered.

In that case javascript shows null. Check that if you are calling the method before the control gets rendered in the page properly or not.

 


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
3/26/2009 12:43:05 PM

Thanks buddy,

You have correctly said, document.getElementByID("<%=TxtDrawnOn.ClientID%>") is working once i have included the JavaScript with HTML markup.

Is there any way to get the client id of a control in external JavaScript file? Or in external file I always have to write

"tl00_ContentPlaceHolder1_TxtDrawnOn".

 

0
varun5318
3/28/2009 6:00:00 AM

varun5318:

Thanks buddy,

You have correctly said, document.getElementByID("<%=TxtDrawnOn.ClientID%>") is working once i have included the JavaScript with HTML markup.

Is there any way to get the client id of a control in external JavaScript file? Or in external file I always have to write

"tl00_ContentPlaceHolder1_TxtDrawnOn".

 

You have to build your JavaScript for include files so that the ID is passed to each function by the caller. For example:

A function that currently looks like this:

function someFunction()
{
 var elementRef = document.getElementById('<%= someElement.ClientID %>');

 ...

and called by: ClientScript.RegisterStartupScript(this.GetType(), "script-key-goes-here", "someFunction();", true);

Must now look like this:

function someFunction(elementId)
{
 var elementRef = document.getElementById(elementId);

 ...

and called by: ClientScript.RegisterStartupScript(this.GetType(), "script-key-goes-here", "someFunction('" + someElement.ClientID + "');", true);

NC...

0
NC01
3/30/2009 11:30:03 AM
Reply:

Similar Artilces:

ScriptManager Work in Client side and not Work in server
 i have this line in my site            ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "script", "call3();", True)when i run my site in client (my computer) its workbut when i copy my site to server not work or function call3(); not callinghow can i solve my problem thanks for alltareq  Hi,tareqmr I am afraid we cannot find out the exact root cause without further information captured when the problem occurs. To troubleshoot this issue, we really need more source code to reproduce the problem...

server side variables in client side javascript
I want to use an ASP.net variable in client side javascript.In regular asp I used hidden fields.what is the best way to do this in ASP.NET ?thx,Intersee my blog at www.Interdevelopments.com and check the future of open mobile widget solutions at www.glowe.org By and large, I personally still use Hidden fields to store information, that either my Javascript function or my code-behind use.  I barely use the RegisterScriptBlock method(s) and that is only for situations where I want to be really dynamic with the client side functionality.  95% of the time, I can still use a...

Client-side validation works, but server-side does not.
Hey all,I have got this text box control on my webform, which has two validators.. 1. RegularExpressionValidator and 2. CustomValidator.Now, RegularExpressionValidator control works if I enable client-script. But somehow it does not work for server-side validation. Any idea why this is happening? This happens to another textbox control on other web form as well which has similar coding. So, to enable the validation at present I can only do client-side validation I guess.  1 <TD> 2 <anthem:TextBox id="txtDatePlannedSurgery" CssClass="aspText" Runat="server" AutoCal...

Client & Server Side ( Server PostBacks Reset Client Data )
Hi, Slight Problem i have bumped into, maybe someone can help me... --TestSlider.aspx--------- <%@ Page Language="C#" %> <script runat="server"> void click(object sender, EventArgs e) { Label1.Text = Label1.Text; if(btnPress.Text=="Press") btnPress.Text = "PRESS"; else btnPress.Text = "Press"; } </script> <html> <head> <script language="JavaScript"> function newSlider(sId) { sCode = '<table border=...

Starting the server application and stopping the server application from the client application
Hi , How do I do it ? I want to start the server application from my client app. After all my jobs are over , when I disconnect from the server, I want to close the server application. Both the client and server applications will be running on the desktop under NT or win95 environment. If the client app is abc.exe and the server app is pqr.exe when the user starts the client app from his desktop, the client should start pqr.exe . Now after finishing all the process when the user closes the client, I want to disconnect from server and close the server pqr then close abc...

Server side Generating and client side executing javascript
Hi,  This is a really basic question.  If one has a piece of code on the server side that generates some javascript, how do you inject and execute this script n the client side?  For example, I have a server side function that inserts a bunch of calls to a the javascript function foo(), such as foo(1); foo(2);.....How can insert these calls into my webpage so that they are executed on a periodic basic.  I assume I would use an script manager tag, and inside this tag I would have an update panel, but am unsure where to go after that.  jerry   Hi, you can in...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, y...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

How to call server side function from client side JavaScript?
I want to call a server-side function, like a button's click event or just another private or public function , from a client-side JavaScript function. How do I do that? thanX AnzIf this post was useful to you, please mark it as answer.ClientSideAsp.Net | Blog Maybe alittle more that you need, but....... 1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false 2) Write the code for the button. 3) Write the following in the PAge_Load event Button1.Attributes.Add("onClick", "myJSFunction(); return false") 4) Copy this javascript...

how to call server side function from client side javascript?
Hi all, I have a image button in the update panel. I would like to call a method from server side (not from webservice) to get the variable when Onclick on the image button is invoked. Is there any way that I can able to access this function from the client script? In using the UpdatePanel, in essence, you're already doing this because there will not be a full postback.  You can make an asynchronous call to your Click method of your ImageButton.  So, what do you want to do with this "variable"?Christopher Reed"The oxen are slow, but the earth is patient."...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

Passing parameter from Javascript(client-side) to server side
Hi guys, I'm having problems with my code. I have a textbox1 and a submit button and another textbox2. When my user enters a value into textbox1 and click submit, the description text should be returned to textbox2. Here's my code: Javascript(client side) : function CheckValue() { var stdNo = document.getElementById('Textbox1'); if (stdNo.value != null) { What to code here to pass the parameter value to my server?? } "TextBox1" runat="server"> "Button1" runat="server" OnClientClick="CheckValue(...

Instantiating an object of a server-side class in client-side JavaScript
Sorry this might be an easy question, but I couldn't find how to do this.I want to define an object like,var myObj = new MyServerSideClass(); MyServerSideClass is defined in the cs code. Is this possible? If it is, how? Thanks in advance.  Checkout the Example of Passing and Returing Complex Types in this doc:http://www.asp.net/AJAX/Documentation/Live/tutorials/ConsumingWebServicesWithAJAXTutorial.aspxLong Live .NETKazi Manzur Rashid (Amit)_________________________Web: http //dotnetshoutout.comBlog: http://weblogs.asp.net/rashidTwitter: http://twitter.com/manzurrashid...

Accessing server-side Datatable object from client-side javascript?
I am working on a control  that generates 2D charts (line,bar,pie,etc) using VML (for now) to draw the charts client-side. I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side.  I am currently using a Sys.Data.Datable on the client side as test data (building the table manually in javascript) and it works fine but I cannot figure how to pass a datatable from the server to the control extension behavior? I have read/seen code on the forums on how to do this using a web-service but I am really looking a...

Web resources about - javascript working on my machine (application server), but not on client. - asp.net.client-side

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Pre-Christmas job application rush hits Australian public service
Speed required for pre-Christmas job window opening for public servants. Check out who is hiring.

Second visa application 'likely' to be approved
The family of a terminally ill Pakistani student can 'hopefully come to Australia sooner rather than later' says Immigration Minister Peter Dutton. ...

Cloud application adoption increases 71 percent in 2015
The adoption of cloud applications is soaring, up by 71 percent in the last year according to the results of a new survey. The latest Cloud ...

Tashfeen Malik's visa application under scrutiny - Business Insider Deutschland
The US government has released the visa application for Tashfeen Malik, who along with her husband killed 14 people in an attack in San Bernardino, ...

MBA: Mortgage Applications Increase in Latest MBA Weekly Survey, Purchase Applications up 37% YoY
From the MBA: Refinance, Purchase Applications Both Up in Latest MBA Weekly Survey Mortgage applications increased 7.3 percent from one week ...

Lawmaker: Immigration Officials Didn’t Fully Vet Tashfeen Malik’s Visa Application
"It’s unacceptable that U.S. Citizenship and Immigration Services did not fully vet Malik’s application and instead sloppily approved her visa," ...

German-Based Spirea Promotes Decentralized PV Applications In Uruguay
... Its technical operations specialist, Laurie Lawrence, pointed out that Uruguay [&hellip German-Based Spirea Promotes Decentralized PV Applications ...

Visa application of San Bernardino shooter released
CNN Visa application of San Bernardino shooter released CNN (CNN) The visa application of one of the San Bernardino shooters was released ...

NTU research team discovers optoelectronic application for molybdenum disulfide
A research team under the National Taiwan University (NTU) has discovered an optoelectronic application for molybdenum disulfide (MoS2), a 2-dimensional ...

Resources last updated: 12/25/2015 1:57:51 PM