Browser Detecting

J

Jaams Adams

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
 
P

Peter Bromberg [C# MVP]

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
 
S

Scott M.

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.
 
J

Jaams Adams

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/QuickSta...e1.src&file=reference1_cs.aspx&lang=C#+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 ????????????????
 
S

Scott M.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top