?
Solved

Correct my Javascript syntax ?

Posted on 2012-03-13
20
Medium Priority
?
365 Views
Last Modified: 2012-03-15
Whats wrong in my following syntax ?

string javascript = "<script type='text/jscript'> " +
"$(document).ready(function () { " +
"$('" + "#" + this.ClientID + "').datepicker('" +
"'{ showOn: '" + "button" +"',buttonImage: '"
+ "images/calendar.gif,buttonImageOnly: true}); ); " 
+ "});</script>";

Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, javascript);
0
Comment
Question by:PeteEngineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 3
  • +1
20 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 800 total points
ID: 37718661
try this..

string javascript = "<script type='text/jscript'> " + 
"$(document).ready(function () { " + 
"$('#" + this.ClientID + "').datepicker(" + 
"{ showOn: 'button',buttonImage: " +
"'images/calendar.gif',buttonImageOnly: true}); ); "+
"});</script>"; 

Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, javascript);

Open in new window

0
 
LVL 15

Assisted Solution

by:santhimurthyd
santhimurthyd earned 1000 total points
ID: 37718714
Tried to fix the issue and felt as it's difficult until we don't as what's your final syntax requirment but follow the steps to correct the syntax

Instead of registering the script usign the
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, javascript);


Declare the string varaible at class level instead of Method level as show below

protected string javascript = string.Empty;

Open in new window


In the .aspx page place the belwo syntaxt to get the Script generated
<%=javascript%>

Open in new window


finally following the step script generated is as follows

 
<script type='text/jscript'> 
            $(document).ready(function () 
            { 
                $('#__Page').datepicker([b]''{ showOn: 'button',buttonImage: 'images/calendar.gif,buttonImageOnly: true}); ); });[/b]            
        </script>

Open in new window


bolded the place where the issue is, If you can possible as what's your expected script will help to fix the syntax error.
0
 
LVL 7

Expert Comment

by:wdfdo1986
ID: 37718724
yeah as ansudhindra corrected you have included some extra quotations there. Best way to test the code is first use it in an test html file and check it.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 8

Author Comment

by:PeteEngineer
ID: 37718825
This  is my expected :

<script>
      $(function() {
            $( "#datepicker" ).datepicker({
                  showOn: "button",
                  buttonImage: "images/calendar.gif",
                  buttonImageOnly: true
            });
      });
      </script>


But the one "ansudhindra"  posted is not working :-(

Please correct and post !
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37718879
Try with this

 javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#datepicker\").datepicker({showOn:\"button\",buttonImage:\"images/calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";
0
 
LVL 7

Assisted Solution

by:wdfdo1986
wdfdo1986 earned 200 total points
ID: 37718897
santhimurthyd's concept is right but as I know to access a variable which is created n the back end code from the front end you need to make it a property. However that's the way I am doing when I wanted to do what you tries to do.

And if you want to continue this try this
string javascript = "<script> $(function() { $(\"" + "#" + this.ClientID + "\").datepicker(\"{ showOn: \"button\", buttonImage: \"images/calendar.gif\" ,buttonImageOnly: true}); }); </script>";
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719047
I'm trying with the Page.register script only and not with the Varaible access

  javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#datepicker\").datepicker({showOn:\"button\",buttonImage:\"images/calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";

            Page.ClientScript.RegisterStartupScript(typeof(string), Guid.NewGuid().ToString(), javascript);


This is the syntax, I did and got error due to non reference to JQuerry Library.

If possible share the error else "Uncheck" the option disbale Javascript debuggin in IE to find where is the error your getting will help us

i) Open IE
ii) Navigate to "Tools" => "Internet Options"
iii) Navigate to "Advance Tab"
iv) Uncheck checkbox "disbale Script Debugging" under the Browser category

share your steps to help further
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719086
santhimurthyd :


Ahhhh..insted of #datepicker i am using client id can u rewrite that for me ?
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719101
Cool , In the below change the bolded text with the respective DataPicker Id

javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#" + <<datepicker>>.ClientID +"\").datepicker({showOn:\"button\",buttonImage:\"images/calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719111
See this :

"$('" + "#" + this.ClientID + "').datepicker('" +
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37719117
make it just
"$('#" + this.ClientID + "').datepicker('" +
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719130
this.ClientID  will return you the page Id as "__Page" to get the Datapicker Control Id, you have to use Datapicker Control Id instead of this.
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719210
no ..its working for the code that i posed above in my question ... u just need to change the syntax ... no change in code contents required ..please put the this.clientid and rewrite the code you have posted
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719341
Almost worked but few more issue


  string javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#" + this.ClientID +"\").datepicker({showOn:\"button\",buttonImage:\"calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";


The above code i have rewritten to read the calender.gif which is not in image folder.
The earlier one was not in image folder. Not its in root folder.

But i am getting an javascript error ..please fix it for me too
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719342
The previous code is working which take image from image folder

the above one is not as i am taking it NOT from image but from root.. :-(
0
 
LVL 7

Expert Comment

by:wdfdo1986
ID: 37719398
Post the JavaScript error
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719438
What's the control Id needs to be in the "$(\"#" + this.ClientID +"\").datepicker because that's the decision one. If you cna explain more will help full

because in your script you have mentioned it have to be as
 $( "#datepicker" ).datepicker({

Where as in code behind implementation client Id of the page is used
"$('" + "#" + this.ClientID + "').datepicker('" +
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719580
I cannot post the error since it is visible

But i need to get the above posted javascript without images folder


i dont want to be like this : ( "#datepicker" ).datepicker({

instead i want to be like this :  $('" + "#" + this.ClientID + "').datepicker('" +
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719808
ok, But could you give more inputs because this.ClientID will always retun the page id
"__Page" , not the "datePicker". so if you can use the control id instead of "this" will create the client id of the control to which the datepicker to be show.

If i'm correct you may mapped the event to button, In that case use the Button Id not this.
0
 
LVL 8

Author Closing Comment

by:PeteEngineer
ID: 37723880
Thanks
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question