Showing posts with label multiple. Show all posts
Showing posts with label multiple. Show all posts

Monday, March 26, 2012

Newbie: Multiple codebehind files

Hi All,

I'm not certain this can be done but it sure seems like it. I'd like to use
multiple C# codebehind files in an aspx page. The idea is that a number of
common functions, like wiring data sources, could be done in a similar
fashion for various controls across multiple pages. What makes sense to me
then would be to have an aspx page that uses a codebehind file. That file
would reference classes in a second file that did the common work.

Assuming I'm on the right track, how would you do this? Is it enough to
simply have both .cs files in the same folder or should each be referenced
in the @dotnet.itags.org.Page's Inherits and Src attributes? Basically, I think the idea
should work, but I'm missing the details on referencing and location.

For example, a control:

<asp:DropDownList id="ddlWidgets" runat="server" /
would be referenced in the codebehind's Page_Load method:

protected void Page_Load( Object Source, EventArgs Args )
{
if (!IsPostBack)
{
WireUpControl( ddlWidgets, "Widgets" );
}
}

where WireUpControl is a method in a class located in a different file that
takes a reference to the control and a table name and binds that table's
data to the control.

TIA,

JohnYou don't need multiple code behinds, just multiple class files if you
will... In which case you can add event handlers etc...

you could have nothing but your event handlers in your code behind that make
reference to other classes.. or, if you have a page that your going to use a
lot of functions a lot... inherit it from system.web.ui.page, creating
your own class with those functions you want.

Then inherit that page into all your otherpages... boom...

This is really effective if you have say a search bar on every page... Just
for example.

-CJ
"John Spiegel" <jspiegel@.c-comld.com> wrote in message
news:unKWETKbDHA.384@.TK2MSFTNGP12.phx.gbl...
> Hi All,
> I'm not certain this can be done but it sure seems like it. I'd like to
use
> multiple C# codebehind files in an aspx page. The idea is that a number
of
> common functions, like wiring data sources, could be done in a similar
> fashion for various controls across multiple pages. What makes sense to
me
> then would be to have an aspx page that uses a codebehind file. That file
> would reference classes in a second file that did the common work.
> Assuming I'm on the right track, how would you do this? Is it enough to
> simply have both .cs files in the same folder or should each be referenced
> in the @.Page's Inherits and Src attributes? Basically, I think the idea
> should work, but I'm missing the details on referencing and location.
> For example, a control:
> <asp:DropDownList id="ddlWidgets" runat="server" />
> would be referenced in the codebehind's Page_Load method:
> protected void Page_Load( Object Source, EventArgs Args )
> {
> if (!IsPostBack)
> {
> WireUpControl( ddlWidgets, "Widgets" );
> }
> }
> where WireUpControl is a method in a class located in a different file
that
> takes a reference to the control and a table name and binds that table's
> data to the control.
> TIA,
> John
Hi John,

Speaking from a C# background, and in an OO sense certainly, you should not
be able to inherit from more than one superclass (unless you are using C or
something). So it makes sense to assume you cannot inherit from more than
one 'codebehind'.

The usual practice is to place commonly used functions in a different
abstract superclass, further up the heirarchy. However, don't lean too
heavily on heirarchies, as they can become difficult to maintain in an
extensibility sense. Consider instead using the strategy pattern as an
alternative?

hth,
Ben

"John Spiegel" <jspiegel@.c-comld.com> wrote in message
news:unKWETKbDHA.384@.TK2MSFTNGP12.phx.gbl...
> Hi All,
> I'm not certain this can be done but it sure seems like it. I'd like to
use
> multiple C# codebehind files in an aspx page. The idea is that a number
of
> common functions, like wiring data sources, could be done in a similar
> fashion for various controls across multiple pages. What makes sense to
me
> then would be to have an aspx page that uses a codebehind file. That file
> would reference classes in a second file that did the common work.
> Assuming I'm on the right track, how would you do this? Is it enough to
> simply have both .cs files in the same folder or should each be referenced
> in the @.Page's Inherits and Src attributes? Basically, I think the idea
> should work, but I'm missing the details on referencing and location.
> For example, a control:
> <asp:DropDownList id="ddlWidgets" runat="server" />
> would be referenced in the codebehind's Page_Load method:
> protected void Page_Load( Object Source, EventArgs Args )
> {
> if (!IsPostBack)
> {
> WireUpControl( ddlWidgets, "Widgets" );
> }
> }
> where WireUpControl is a method in a class located in a different file
that
> takes a reference to the control and a table name and binds that table's
> data to the control.
> TIA,
> John
"John Spiegel" <jspiegel@.c-comld.com> wrote in message
news:unKWETKbDHA.384@.TK2MSFTNGP12.phx.gbl...
> Hi All,
> I'm not certain this can be done but it sure seems like it. I'd like to
use
> multiple C# codebehind files in an aspx page. The idea is that a number
of
> common functions, like wiring data sources, could be done in a similar
> fashion for various controls across multiple pages. What makes sense to
me
> then would be to have an aspx page that uses a codebehind file. That file
> would reference classes in a second file that did the common work.

John,

There are "CodeBehind" files, which are the .aspx.cs files. These are the
"other side" of the .aspx files.

Your web project can contain classes which are not related to a single page.
You can always add these separate classes in .cs files and then reference
them from your codebehind (.aspx.cs) files.
--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com
Thanks guys. Just the kind of stuff I'm needing.

Desperately looking forward to the day when I can honestly drop the
"Newbie:" tag on my subjects... <g
- John

"John Spiegel" <jspiegel@.c-comld.com> wrote in message
news:unKWETKbDHA.384@.TK2MSFTNGP12.phx.gbl...
> Hi All,
> I'm not certain this can be done but it sure seems like it. I'd like to
use
> multiple C# codebehind files in an aspx page. The idea is that a number
of
> common functions, like wiring data sources, could be done in a similar
> fashion for various controls across multiple pages. What makes sense to
me
> then would be to have an aspx page that uses a codebehind file. That file
> would reference classes in a second file that did the common work.
> Assuming I'm on the right track, how would you do this? Is it enough to
> simply have both .cs files in the same folder or should each be referenced
> in the @.Page's Inherits and Src attributes? Basically, I think the idea
> should work, but I'm missing the details on referencing and location.
> For example, a control:
> <asp:DropDownList id="ddlWidgets" runat="server" />
> would be referenced in the codebehind's Page_Load method:
> protected void Page_Load( Object Source, EventArgs Args )
> {
> if (!IsPostBack)
> {
> WireUpControl( ddlWidgets, "Widgets" );
> }
> }
> where WireUpControl is a method in a class located in a different file
that
> takes a reference to the control and a table name and binds that table's
> data to the control.
> TIA,
> John

Thursday, March 22, 2012

Newby/Novice Question: Printing Web Pages...

Hello, I have a question for the group.
My current project uses multiple panels to display the contents of a
web page. The thing is many of these panels are hidden while only one
is visible at a time (much like tabs). I use a set of command buttons
to switch between these panels. What I would like to do is to create a
print function that will create a preview showing all panels in
sequential order which could be used to print a hard copy.
Any suggestions?
TIA...The simple answer is: Use CSS to do the dirty work
You can set up different stylesheets for screen and print (an example
to follow)
BUT:
It all depends on your app
Is all your data easily available upfront? is there a lot of overhead
involved in fecthing data to be displayed on the other "tab"s
Are your clients on a low latency connection to the server?
EXAMPLE:
<STYLE type="text/css">
@.media print { .ScreenOnly { display: none; } }
@.media screen { .PrintOnly { display: none; }
.TabContentHidden { display: none; visibility: hidden; } }
</STYLE>
<DIV class="ScreenOnly" >This content will not be printed</DIV>
<DIV class="PrintOnly" >This content will not be visible on screen, but
<B>will</B> be printed</DIV>
<DIV class="TabContentHidden" >This is an invisible panel (but will
print)</DIV><DIV class="TabContent" >This is the visible panel (both
print and screen)</DIV>
<DIV class="TabContentHidden" >This is an invisible panel (but will
print)</DIV>
The other advantage to this approach is that you can switch "tabs" on
the browser without the server roundtrips (read near-instantaneous)
Hope this helps
-- addup --
Hmmm.
That looks interesting and might work if I had things setup "normally"
but that approch wouldn't work, I think. I am using ASPdotNET (i.e.
postbacks) to make the different panels/DIVs visible or not. If a
panel is not set as visible by the server it doesn't even show up on
the client side.
Private Sub btnPg1_Click(sender as Object, e as EventArgs) Handles
btnPg1.Click
pnlPg1.Visible = True
pnlPg2.Visible = False
pnlPg3.Visible = False
pnlPg4.Visible = False
pnlPg5.Visible = False
End Sub
Is there perhaps more of a dotNET approach?
TIA...
I guess I should lookup more on that CSS stuff.
You will have to change from ASP.Net Visibility to CSS visiblity:
pnlPg1.Visible = true
pnlPg1.Attributes.Add("display", "");
pnlPg2.Visible = true
pnlPg2.Attributes.Add("display", "none");
pnlPg3.Visible = true
pnlPg3.Attributes.Add("display", "none");
pnlPg4.Visible = true
pnlPg4.Attributes.Add("display", "none");
then in your HTML add
<link href="http://links.10026.com/?link=print.css" type="text/css" rel="stylesheet" media="print">
print.css:
--
#pnlPg1 { display:; }
#pnlPg2 { display:; }
#pnlPg3 { display:; }
#pnlPg4 { display:; }
#pnlPg5 { display:; }
When you change the Visible Property in .NET it doesn't ever render the
control to the browser. If you have all the Visible Properties set to true
and use the css style display attribute = "" (blank-visible) or "none"
(invisible). Then every panel is rendered to the browser and you control
the visiblity on the client side using CSS
So the page uses the default CSS from you code on the screen layout, then
when you print using the it uses the printCSS and will make all panels
visible.
Let us know if this works.
what's "normal" anyway.
While *I* wouldn't do it this way, there's nothing wrong with your
approach
For your case
Set up another command button btnPrint
Private Sub btnPrint_Click(sender as Object, e as EventArgs) Handles
btnPrint.Click
pnlPg1.Visible = True
pnlPg2.Visible = True
pnlPg3.Visible = True
pnlPg4.Visible = True
pnlPg5.Visible = True
Page.RegisterStartupScript("PrintScript", "<SCRIPT
language='javascript'>window.print(); history.back();</SCRIPT>")
End Sub
I would probably have to agree. Setting up a print page would definately be
cleaner
JavaScript to the rescue!...again
I remember using a LOT of JavaScript with ASP.Classic
That gave me something to work with.
Thanks.
Ben Dewey wrote:
> I would probably have to agree. Setting up a print page would definately
be
> cleaner

Friday, March 16, 2012

Newline with HTMLEncode in Div and Label

Hi

I have a table column that has multiple lines (\r\n) and html tags in it. I
want to display it in a div and label that html tags can be seen and
newlines should work.
If i use div.innerHTML newlines are lost and html tags doesn't show.
If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks works
but html tags doesn't show.
If i use div.innerText again newlines and html tags are lost.

What can i do?

ThanksVersus,
The bottom line is that "\r\n" means nothing in HTML - you have to change it
to "<br/>" -- which means you need to pre-process your string with
..Replace("\r\n", "<br/>");

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"versus" wrote:

Quote:

Originally Posted by

Hi
>
I have a table column that has multiple lines (\r\n) and html tags in it. I
want to display it in a div and label that html tags can be seen and
newlines should work.
If i use div.innerHTML newlines are lost and html tags doesn't show.
If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks works
but html tags doesn't show.
If i use div.innerText again newlines and html tags are lost.
>
What can i do?
>
Thanks
>
>
>


Thanks for answering. Replace(Environment.NewLine,"<br>") already works for
that problem. But i cannot see html tags as regular text. I want them to be
displayed not parsed with htmlparser.

Let me explain again. I have an sql db table with columns that has both
environment.newline(\r\n) and html tags. I want newlines to break lines and
html tags to be displayed at the same time.

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yohohhoandabottleofrum.comwrote
in message news:4CA1F3DF-BB2B-479B-8025-69154C4984C5@.microsoft.com...

Quote:

Originally Posted by

Versus,
The bottom line is that "\r\n" means nothing in HTML - you have to change
it
to "<br/>" -- which means you need to pre-process your string with
.Replace("\r\n", "<br/>");
>
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
>
>
>
"versus" wrote:
>

Quote:

Originally Posted by

>Hi
>>
>I have a table column that has multiple lines (\r\n) and html tags in it.
>I
>want to display it in a div and label that html tags can be seen and
>newlines should work.
>If i use div.innerHTML newlines are lost and html tags doesn't show.
>If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks
>works
>but html tags doesn't show.
>If i use div.innerText again newlines and html tags are lost.
>>
>What can i do?
>>
>Thanks
>>
>>
>>


"versus" <tencere@.dibin.karawrote in message
news:ee99xTJGIHA.4808@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Thanks for answering. Replace(Environment.NewLine,"<br>") already works
for that problem. But i cannot see html tags as regular text. I want them
to be displayed not parsed with htmlparser.
>
Let me explain again. I have an sql db table with columns that has both
environment.newline(\r\n) and html tags. I want newlines to break lines
and html tags to be displayed at the same time.
>
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yohohhoandabottleofrum.com>
wrote in message
news:4CA1F3DF-BB2B-479B-8025-69154C4984C5@.microsoft.com...

Quote:

Originally Posted by

>Versus,
>The bottom line is that "\r\n" means nothing in HTML - you have to change
>it
>to "<br/>" -- which means you need to pre-process your string with
>.Replace("\r\n", "<br/>");
>>
>-- Peter
>Recursion: see Recursion
>site: http://www.eggheadcafe.com
>unBlog: http://petesbloggerama.blogspot.com
>BlogMetaFinder: http://www.blogmetafinder.com
>>
>>
>>
>"versus" wrote:
>>

Quote:

Originally Posted by

>>Hi
>>>
>>I have a table column that has multiple lines (\r\n) and html tags in
>>it. I
>>want to display it in a div and label that html tags can be seen and
>>newlines should work.
>>If i use div.innerHTML newlines are lost and html tags doesn't show.
>>If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks
>>works
>>but html tags doesn't show.
>>If i use div.innerText again newlines and html tags are lost.
>>>
>>What can i do?
>>>
>>Thanks
>>>
>>>
>>>


>
>


I think if you use the <pretag to wrap your code it will honor the CRLF
and show the tags as if they are text within the <pre></pretags.

Hope this helps
LS
I think if you use the <pretag to wrap your code it will honor the CRLF

Quote:

Originally Posted by

and show the tags as if they are text within the <pre></pretags.
>
Hope this helps
LS


Thanks but his solution removes css classes and when i use checkbox with
label, label click doesn't work.
On Sat, 27 Oct 2007 04:55:00 -0700, Peter Bromberg [C# MVP]
<pbromberg@.yahoo.yohohhoandabottleofrum.comwrote:

Quote:

Originally Posted by

>Versus,
>The bottom line is that "\r\n" means nothing in HTML - you have to change it
>to "<br/>" -- which means you need to pre-process your string with
>.Replace("\r\n", "<br/>");
>
>-- Peter
>Recursion: see Recursion
>site: http://www.eggheadcafe.com
>unBlog: http://petesbloggerama.blogspot.com
>BlogMetaFinder: http://www.blogmetafinder.com


Actually, newlines may make a lot of sense when you want your HTML to
be easily understood if you do a view source on the html page ...

--
http://bytes.thinkersroom.com
On 27 okt, 14:54, "Lloyd Sheen" <a...@.b.cwrote:

Quote:

Originally Posted by

"versus" <tenc...@.dibin.karawrote in message
>
news:ee99xTJGIHA.4808@.TK2MSFTNGP05.phx.gbl...
>

Quote:

Originally Posted by

Thanks for answering. Replace(Environment.NewLine,"<br>") already works
for that problem. But i cannot see html tags as regular text. I want them
to be displayed not parsed with htmlparser.


>

Quote:

Originally Posted by

Let me explain again. I have an sql db table with columns that has both
environment.newline(\r\n) and html tags. I want newlines to break lines
and html tags to be displayed at the same time.


>

Quote:

Originally Posted by

"Peter Bromberg [C# MVP]" <pbromb...@.yahoo.yohohhoandabottleofrum.com>
wrote in message
news:4CA1F3DF-BB2B-479B-8025-69154C4984C5@.microsoft.com...

Quote:

Originally Posted by

Versus,
The bottom line is that "\r\n" means nothing in HTML - you have to change
it
to "<br/>" -- which means you need to pre-process your string with
.Replace("\r\n", "<br/>");


>

Quote:

Originally Posted by

Quote:

Originally Posted by

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com


>

Quote:

Originally Posted by

Quote:

Originally Posted by

"versus" wrote:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>Hi


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>I have a table column that has multiple lines (\r\n) and html tags in
>it. I
>want to display it in a div and label that html tags can be seen and
>newlines should work.
>If i use div.innerHTML newlines are lost and html tags doesn't show.
>If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks
>works
>but html tags doesn't show.
>If i use div.innerText again newlines and html tags are lost.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>What can i do?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>Thanks


>
I think if you use the <pretag to wrap your code it will honor the CRLF
and show the tags as if they are text within the <pre></pretags.
>
Hope this helps
LS


That's correct but the problem lies elsewhere.
If you update a <pretag with innerHTML, Internet Explorer will
remove the \n's before it's in the <pretag.