asp.net c# generate user control parameters -


asp.net new me , i've been handed existing project work on. wrote so: asp.net webforms - how pass viewdata param user control must not have been clear there no responses.

i want this:

consignment.ascx:  <%@ control language="c#" inherits="system.web.mvc.viewusercontrol<daff.lae.tracecommon.valueobjects.noirepronls.noinlsvo>" %> <%@ register tagprefix="uc" tagname="speciesgrid" src="~/views/noi/repronls/speciesgridcontroller.ascx" %>  <%     var applicationid = viewdata["noiid"];     var applicationspecies = viewdata["applicationspecies"] hashset<string>;    // same js var applicationspecies server - needed build page %>  ...  <%     foreach (string species in applicationspecies)     {         %>         <div id="<%=species%>_grid" style="display: none;">             <uc:speciesgrid runat="server" species=<%=species%>/>         </div>     <%} %> 

but fails on <%=species%> in <uc:speciesgrid with:

{"server tags cannot contain <% ... %> constructs."} 

the user control:

speciesgridcontroller.ascx  <%@ control language="c#" classname="speciesgrid" %> <%@ import namespace="kendo.mvc.ui" %> <%@ import namespace="daff.lae.tracecommon.valueobjects.noirepronls" %> <%@ import namespace="system.diagnostics" %>  <script runat="server">     private idictionary<string, object> readroutevaluedictionary = new dictionary<string, object>();     private int _applicationid;     private string _species;      public string species     {         set         {             if (!value.isempty())             {                 _species = value;                 readroutevaluedictionary.add("species", value);             }         }                 {             return _species;         }         ...     } </script>  <fieldset>     <legend><%=species%></legend>     <div>         <% html.kendo().grid<noinlsconsignmentvo>()                .name("grdnlsconsignment"+species)                ...         %>     </div> </fieldset> 

how 1 <uc:speciesgrid runat="server" species=<%=species%>/> work?

thanks @tetsuya yamamoto comment. here came with.

i think speciesgridview.ascx better code behind object rather include <script ... block. me play with.

consignment.ascx  <%     var applicationid = viewdata["noiid"];     var allspecies = viewdata["allspecies"] list<listitem>;        %> ...  <% foreach (listitem speciesitem in allspecies) {     var species = speciesitem.value.replace(" ", "_");%>     <div id="<%=species%>_grid" style="display: none;">         <%             html.renderpartial("~/views/noi/repronls/speciesgridview.ascx", new speciesgridviewdto( noiid : (int) applicationid, speciescode : species));         %>     </div> <%}%> 

speciesgridviewdto.cs  using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.serialization;  namespace daff.lae.tracecommon.dto.noirepronls {     /// <summary>     /// datatransferobject sending succinct model speciesgridview     /// </summary>     [datacontract, serializable]     public class speciesgridviewdto     {         [datamember]         public int32 noiid { get; set; }          [datamember]         public string speciescode { get; set; }          public speciesgridviewdto(int noiid, string speciescode)         {             this.noiid = noiid;             this.speciescode = speciescode;         }     } } 

speciesgridview.ascx  <%@ control language="c#" inherits="system.web.mvc.viewusercontrol<daff.lae.tracecommon.dto.noirepronls.speciesgridviewdto>"%> <%@ import namespace="daff.lae.tracecommon.valueobjects" %>  <%@ import namespace="kendo.mvc.ui" %> <%@ import namespace="daff.lae.tracecommon.valueobjects.noirepronls" %> <%@ import namespace="system.diagnostics" %>   <%-- speciesgrid - render kendogrid of noinlsconsignmentvo.  --%>  <script runat="server">     private idictionary<string, object> readroutevaluedictionary = new dictionary<string, object>();      protected void page_load(object sender, eventargs e)     {         readroutevaluedictionary.add("applicationid", model.noiid);         // speciescode optional.  if not given species used.         if (! model.speciescode.isempty())         {             readroutevaluedictionary.add("species", model.speciescode);         }     } </script> <fieldset>     <legend><%=model.speciescode%></legend>     <div>     <% html.kendo().grid<noinlsconsignmentvo>()               .name("grdnlsconsignment"+model.speciescode)               ... 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -