Home All Groups Group Topic Archive Search About
Author
17 Jan 2007 6:59 PM
David Thielen
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

Author
18 Jan 2007 6:54 AM
Steven Cheng[MSFT]
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.
Author
18 Jan 2007 10:12 PM
Beemer Biker
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message
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

I have been watching this because I am a newbie and it seems to be it would
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
=======================================================================
Author
19 Jan 2007 1:46 AM
Steven Cheng[MSFT]
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.
Author
19 Jan 2007 4:13 PM
Beemer Biker
Show quote Hide quote
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message
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.
>

Thanks Stephen.  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 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,
>
> 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?
>

I had to prepend the location of the sql server to a bunch of urls used in
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
=======================================================================
Author
22 Jan 2007 12:40 PM
Steven Cheng[MSFT]
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.
Author
23 Jan 2007 3:30 PM
Beemer Biker
THANKS THANKS THANKS!

Show quoteHide quote
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message
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?

This worked fine.  I had no idea that once I defined that ConstantUtil
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
> 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
> }

I had to put "static public string ServiceUrl" or the jscript below would
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>
> .......