Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Browser Detecting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jaams Adams - 03 Feb 2008 00:55 GMT
I have following code in asp.net page.

These are two two different ascx pages which I want to run if the browser is
IE or Not. Here I want to handle the flow of control in bettween HTML coding
by put asp.net delimiter

Can someone help me with why it's calling both ascx pages instead which ever
user agent is there

<td valign="top">

<% if (Request.Browser.Browser == "IE"){%>

   <uc1:MainLeftIE ID="LeftPanelIE" runat="server" EnableViewState="false"
/>

<%} else{%>

   <uc1:MainLeftNon ID="LeftPanelNon" runat="server"
EnableViewState="false" />

<%}%>

</td>

Thanks
Peter Bromberg [C# MVP] - 03 Feb 2008 01:37 GMT
First, an "ASCX" is not a Page, technically it is called a UserControl.
Secondly, I am not sure that the kind of declarative - mixed with
programmatic format you are using here will work. Try doing this is the
codebehind with the LoadControl method instead. In this manner, you do not
have to have any declarative markup at all.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> I have following code in asp.net page.
>
[quoted text clipped - 22 lines]
>
> Thanks
Scott M. - 03 Feb 2008 05:53 GMT
Ouch!  I haven't seen such ugly spaghetti code since classic ASP & server
includes.

I don't think you can use script delimited "if" logic with user control tag
declarations.

>I have following code in asp.net page.
>
[quoted text clipped - 22 lines]
>
> Thanks
Jaams Adams - 03 Feb 2008 23:09 GMT
Follow this page for an example at asp.net website about this kind of coding
functionality
<%@ Page Language="C#" %>
<html>
  <body>
     <% for (int i=0; i<8; i++) { %>
        <font size="<%=i%>"> Hello World! </font> <br>
     <% } %>
  </body>
</html>

and here is the link:
http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples
/pages/reference/reference1.src&file=reference1_cs.aspx&lang=C%23+Source


and this kind of coding is described by microsoft as "Code rendering blocks"

follow the description here:
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/pages/syntax.aspx#expressions

So why isn't my coding working ????????????????

> Ouch!  I haven't seen such ugly spaghetti code since classic ASP & server
> includes.
[quoted text clipped - 28 lines]
>>
>> Thanks
Scott M. - 04 Feb 2008 00:15 GMT
I know what the coding is.  It's also more commonly referred to as
"inline-coding".

Some will tell you that it's perfectly fine and others (like myself) will
tell you to steer clear of it as it creates a jumbled mess (called
"spaghetti code") that is difficult to troubleshoot (as you are finding
out).  This was the only way to write server-side code back in what we now
call "Classic ASP", which was about 7 years ago. Now, we have a choice.

IMHO, there really isn't any reason to EVER write code as you've shown
below.  It can all be written separately from your actual page content.

As for your original question, I believe I answered it when I said that I
don't believe your conditional inline-code can be used with user controls in
the way you are trying to use it.  I believe it has to do with the order in
which the controls are rendered vs. when your "if" logic is being processed.

You may want to consider a good, old-fashioned browser re-direct to a page
that has the appropriate user control on it based on the browser you've
sniffed.

-Scott

> Follow this page for an example at asp.net website about this kind of
> coding functionality
[quoted text clipped - 50 lines]
>>>
>>> Thanks
Coskun SUNALI [MVP] - 04 Feb 2008 01:06 GMT
Hi Jaams,

You should consider using Control Adapters and Browser Definition files
supported by ASP.NET.

For more information, please refer to the following pages.

http://technet.microsoft.com/en-us/library/system.web.ui.adapters.controladapter.aspx

http://msdn2.microsoft.com/en-us/library/ms228122.aspx

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

>I have following code in asp.net page.
>
[quoted text clipped - 22 lines]
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.