|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
#include for a DropDownList?Hi;
We need to set a list of countries for a DropDownList. I don't want to put that in the aspx file as the list is looooooong. Is there some way to do a #include equivilent to pull those in from another file? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com Cubicle Wars - http://www.windwardreports.com/film.htm Hello Dave,
If you do not want to statically embed the list items in aspx template, do you think databinding a possible approach? So far I haven't ever used any #include like means for such scenario. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message I have been watching this because I am a newbie and it seems to be it would news:ezS8P2sOHHA.2300@TK2MSFTNGHUB02.phx.gbl... > Hello Dave, > > If you do not want to statically embed the list items in aspx template, > do > you think databinding a possible approach? So far I haven't ever used any > #include like means for such scenario. > > Sincerely, > > Steven Cheng really be nice to just use an include file like Dave wanted. Googling one can find "how to fake a c# include" so can I assume the lack of an include seems to be a "real feature" in programming an asp page? I did see a suggestion to use a global static. OK, but if I define a bunch of global stuff in some C# page, how can I use that same stuff in the jscript page or vice versa? -- ======================================================================= Joseph "Beemer Biker" Stateson http://ResearchRiders.org Ask about my 99'R1100RT ======================================================================= Thanks for your input Joseph,
Hi Dave, Actually, the server-side include does be a feature involved from classic ASP page. In ASP.NET page, you can still use it for plain html element. e.g. =========== <select id="clientList" runat="server"> <!--#include file = "list.inc" --> </select> ========== ====list.inc======== <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> =================== However, it is not quite recommended if you will use it for pure ASP.NET server control. Joseph, For the following question you mentioned: >>>>>>>>> I did see a suggestion to use a global static. OK, but if I define a bunch of global stuff in some C# page, how can I use that same stuff in the jscript page or vice versa <<<<<<<<<< would you explain it further or do you want to know how to bind the data in C# global variable into ASP.NET page's content/output? Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights.
Show quote
Hide quote
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message Thanks Stephen. Occassionally I have a list of delimited strings and would news:JV7T%23u2OHHA.2304@TK2MSFTNGHUB02.phx.gbl... > Thanks for your input Joseph, > > Hi Dave, > > Actually, the server-side include does be a feature involved from classic > ASP page. In ASP.NET page, you can still use it for plain html element. > e.g. > > =========== > <select id="clientList" runat="server"> > <!--#include file = "list.inc" --> > </select> > ========== > > ====list.inc======== > > <option value="1">1</option> > <option value="2">2</option> > <option value="3">3</option> > <option value="4">4</option> > <option value="5">5</option> > <option value="6">6</option> > <option value="7">7</option> > =================== > > However, it is not quite recommended if you will use it for pure ASP.NET > server control. > like to get them into a C# page. This is usually for testing purposes as I need a quick source of data to test out some code. However, I can just as well copy and paste it into the code. If the "include file" had, for example, 5000 items, then the c# code would be less readable. The subject "#include" just caught my attention as it seems there is no C# include like there is in C or C++. Show quoteHide quote > Joseph, I had to prepend the location of the sql server to a bunch of urls used in > > For the following question you mentioned: > >>>>>>>>>> > I did see a suggestion to use a global static. OK, but if I define a > bunch > of global stuff in some C# page, how can I use that same stuff in the > jscript page or vice versa > <<<<<<<<<< > > would you explain it further or do you want to know how to bind the data > in > C# global variable into ASP.NET page's content/output? > the default.aspx.cs page and the default.aspx (jscript). The server location kept changing and I came up with a quick solution as follows: ========in default.aspx.cs public partial class _Default : System.Web.UI.Page { static string strHostNameUrl = "http://acqlib.electro.swri.edu/"; ========in default.aspx <script language="javascript" type="text/javascript"> var strHostNameUrl = "http://acqlib.electro.swri.edu/" I would like to have just one definition of strHostNameUrl so it needs to be changed in only once place but do not see how to do that in both C# and jscript using global definitions. The only solution I see is to pass in the url as an additional arguement when the grid row is bound and I set up the onclick attributes. That is cleaner but not as easy to implement as merely defining the url to be pre-pended. If there is a way to share constants between C# and jscript (ie: across default.aspx.cs and default.aspx) I would be interested. If I put something into web.config can both access it? -- ======================================================================= Joseph "Beemer Biker" Stateson http://ResearchRiders.org Ask about my 99'R1100RT ======================================================================= Thanks for your reply Joseph,
For your two questions: 1) Occassionally I have a list of delimited strings and would like to get them into a C# page. This is usually for testing purposes as I need a quick source of data to test out some code. However, I can just as well copy and paste it into the code. ======================================== If just for test purpose, another option would be define a utility class which use some public methods(static or non-static) to return some list of data items. And for any test page want to use those data, you can simply drag a ObjectDataSource on the page and use ObjectDataSource to reference that utility class. And those databound control like DropdownList, GridView .... can directly use that objectdatasource to populate test data. How do you think? 2) For the global server url question, I think you can use a similar way which can synchronize the value better. Define a public utility class which use static variables to hold the const url string. And in page template, you can use server-side expression to render out the static const variable to client script fragement. e.g. =======util class======= namespace TestNS { public class ConstantUtil { public } ......... } =============== =====aspx template======== <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> var url = '<%= TestNS.ConstantUtil.ServiceUrl %>'; </script> ........ ======================= Hope this helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead This posting is provided "AS IS" with no warranties, and confers no rights. THANKS THANKS THANKS!
Show quoteHide quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message This worked fine. I had no idea that once I defined that ConstantUtil news:tDmN6JiPHHA.2488@TK2MSFTNGHUB02.phx.gbl... > Thanks for your reply Joseph, > > For your two questions: > > 1) Occassionally I have a list of delimited strings and would > like to get them into a C# page. This is usually for testing purposes as > I > need a quick source of data to test out some code. However, I can just as > well copy and paste it into the code. > ======================================== > If just for test purpose, another option would be define a utility class > which use some public methods(static or non-static) to return some list of > data items. And for any test page want to use those data, you can simply > drag a ObjectDataSource on the page and use ObjectDataSource to reference > that utility class. And those databound control like DropdownList, > GridView > ... can directly use that objectdatasource to populate test data. How do > you think? class, it would show up as a DataSource. The first time I ever looked at an ObjectDataSource its properties had an empty list for sources. I didnt know that defining a class would populate that list. Show quoteHide quote > 2) For the global server url question, I think you can use a similar way I had to put "static public string ServiceUrl" or the jscript below would > which can synchronize the value better. Define a public utility class > which > use static variables to hold the const url string. And in page template, > you can use server-side expression to render out the static const variable > to client script fragement. e.g. > > > > =======util class======= > namespace TestNS > { > public class ConstantUtil > { > public > } give an error. Leaving off static the C# still worked, but not the jscript. Thanks again, I learned quite a byte today! Show quoteHide quote > ........ > } > > =============== > > =====aspx template======== > <html xmlns="http://www.w3.org/1999/xhtml" > > <head runat="server"> > <title>Untitled Page</title> > <script type="text/javascript"> > var url = '<%= TestNS.ConstantUtil.ServiceUrl %>'; > </script> > .......
What's the new thing after ActiveX?
AJAX n00b - custom server control in an UpdatePanel causes full postback Collection Property in web custom control Menu - Eliminate The Triangular Arror pointer thing - How to do it? Web page size Programmatically modifying the controls in FormView's PagerTemplate CSS substitution for the <center> tag Setting name=, ID= for TextBox Gridview only displays 3 columns of 11 column dataset Gridview controls added programmatically does not appear later |
|||||||||||||||||||||||