asp.net mvc 2 - How to run a javascript before server code is run MVC2 -


ok, thing this,

i have view wich renders chart ( .net charts ) , want chart same size web browser window ( browser ie 9 ).

i have tried several examples none works me. since chart gets rendered image, need know size of browser before charts gets rendered ( happens on server side ).

my intention people can create chart sending parameters thru url having values view or controller not option.

is there way this? here view code

<%@ page title="" language="c#" masterpagefile="~/views/shared/charts.master" inherits="system.web.mvc.viewpage<kpidatabase.models.chartmodel>" %>  <asp:content id="content1" contentplaceholderid="titlecontent" runat="server"> </asp:content>  <asp:content id="content2" contentplaceholderid="maincontent" runat="server">  <%if (model.series != null) {          system.web.ui.datavisualization.charting.chart chart1 = new system.web.ui.datavisualization.charting.chart();  chart1.width = 1400; -> values need dynamic  chart1.height = 1100;-> values need dynamic    ... code generating chart....  // render chart control chart1.page = this; htmltextwriter writer2 = new htmltextwriter(page.response.output); chart1.rendercontrol(writer2);                                  }%>   </asp:content> 

any appreciated. searching in internet have found can achieved thru javascript. if run script:

    <script type="text/javascript">      function getwidth() {         var width = $(window).width();}     return width, height ;  </script>   <script type="text/javascript">      function getheigth() {         var height = $(window).height();}     return height ;   </script> 

and use values render chart, great.

at end used ajax perform this.

<script type="text/javascript"> $(document).ready(function () {     var width = screen.width;     var height = screen.height;     $.ajax({         type: "get",         url: "/charts/chart",         data: { 'width': width, 'height': height },         success: function () {         }     }); });  


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -