Click here to Skip to main content
13,142,182 members (53,822 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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;

divME.Attributes("Width") = someValue

What am I missing?
Posted 24-Jan-13 9:54am
Updated 24-Jan-13 11:16am
Idle_Force 24-Jan-13 16:40pm
I will try those suggestions, but my first problem its not recognizing the javascript function name
Rate this: bad
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:[^].

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.

Idle_Force 24-Jan-13 17:16pm
Idle_Force 24-Jan-13 17:28pm
Can you tell me why my javascript is not recognised?
Sergey Alexandrovich Kryukov 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?
Idle_Force 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
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...):


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2017
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