Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
I have two divs I want to set the width dynamically to the size of the gridViews. I have tried two ways, bit new with javascript. I get error that states 'setWidths' is not a member of *.aspx. My requirements are to center the GridViews which I have tried with css(.Middle{margin-left:auto;margin-right:auto;position:relative;}) which does not work - however the div element does respond to this as long as it has a width defined.
 
<script language="javascript" type="text/javascript" >
       function setWidths() {
       $('divME').width = $('gvME').width;
       $('divDE').width = $('gvDE').width;
       return;}
   </script>
 
divME.Attributes("Width") = someValue
 
What am I missing?
Posted 24-Jan-13 10:54am
Edited 24-Jan-13 12:16pm
v2
Comments
Idle_Force at 24-Jan-13 16:40pm
   
I will try those suggestions, but my first problem its not recognizing the javascript function name
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First problem I can see is: jQuery selectors are wrong. You are using the syntax of element selectors but there are no such elements as "divME", "divDE", etc. Did you mean "#divME" (id) or something else? Please see to fix it:
http://api.jquery.com/category/selectors/[^].
 
Also I would advise to use more complex layout and CSS instead of JavaScript. Then the width will be adjusted without any scripting. You need to read about CSS box model and related topics. As I don't know your layout requirements, I cannot help you in more detail at this moment.
 
—SA
  Permalink  
v2
Comments
Idle_Force at 24-Jan-13 17:16pm
   
Updated!
Idle_Force at 24-Jan-13 17:28pm
   
Can you tell me why my javascript is not recognised?
Sergey Alexandrovich Kryukov at 24-Jan-13 17:32pm
   
What is update, where and how, and why do you think I need to know about it?
What do you mean by "not recognized"?
Can you use JavaScript debugger to see what's going on?
—SA
Idle_Force at 24-Jan-13 19:17pm
   
Updated info - cause most here appreciate when we supply more info??? When I type in the name of the javascript function in the OnClick of a button, example, I get an error saying it does not exist on the page during runtime. I have followed some examples from w3schools with intermittent luck.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Your selectors do not look right. You would need to do something like $('#divME') for div. Does your grid stay on a page that has a master page? if so the id selector will be different. Therefore you could do $('id$="gvME"').
 
With that, you are also probably after the width with units. the ".width" will only return the number without units so this may not work.
 
try something like (not tested and im not javascript expert but...):
 
$('#divME').css.width($('id$="gvME"').css.width());
 
http://api.jquery.com/width/[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100