1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

New to ASP.net

Discussion in 'C#' started by yorks45, Jan 2, 2007.

  1. #1
    Hi all

    I have just started to learn ASP.net and struggling a bit :) Its probably really simple to do this but I cannot work it out.

    I want to assign some text to a variable according to the value of a querystring and then display this text. I have shown the relevant code below


    if(Request["CategoryID"]!="8")
    {
    string ptitle = "SLR cameras";
    }


    I then want to show the value of ptitle but when i do I get the following error


    Compiler Error Message: CS0103: The name 'ptitle' does not exist in the class or namespace 'ASP.testcat_aspx'

    Source Error:

    Line 39: <html>
    Line 40: <head>
    Line 41: <title><%=(ptitle)%></title>
    Line 42: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    Line 43: <!--[if IE]>


    any help would be much appreciated

    thanks
     
    yorks45, Jan 2, 2007 IP
  2. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #2
    You should dump the old ASP way of thinking ...

    In your aspx file, you should have controls ... For example a literal control ...

    <asp:Literal runat="server" id="ptitle" />

    Then you can change the text using ptitle.Text = "Something"
     
    kajakske, Jan 2, 2007 IP
  3. yorks45

    yorks45 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply. I have tried what you suggested but get the following error

    Compiler Error Message: CS0117: 'System.Web.UI.WebControls.Literal' does not contain a definition for 'text'

    Source Error:

    Line 29: if(Request["CategoryID"]!="8")
    Line 30: {
    Line 31: ptitle.text = "SLR cameras";
    Line 32: }
    Line 33:
     
    yorks45, Jan 2, 2007 IP
  4. serversidescripter

    serversidescripter Banned

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    what is the data type of your CategoryID is that an integer of a string?
     
    serversidescripter, Jan 2, 2007 IP
  5. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #5
    try it.

    if(Request("CategoryID")!="8") then
    ptitle.text = "SLR cameras"
    end if
     
    YIAM, Jan 2, 2007 IP
  6. yorks45

    yorks45 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Still having probs ....here is the code I am using



    <asp:Literal runat="server" id="ptitle" />

    <script language=C# runat=server>
    private DataTable dtSubCategories;
    private DataTable dtProducts;
    private DataTable dtProductVariants;
    private Product ObjProduct = null;
    private int CategoryID;
    private bool IsStockedAccessories = false;

    private void Page_Load(object sender, System.EventArgs e)

    {
    if((Request["CategoryID"]!=null)&&(Request["CategoryID"]!=""))
    {
    ObjProduct = new Product();
    CategoryID = Convert.ToInt32(Request["CategoryID"]);
    ObjProduct.CategoryID = CategoryID;
    dtSubCategories = ObjProduct.GetSubCategories();
    }


    }
    </script>

    <%
    if(Request("CategoryID")!="8") then
    ptitle.text = "SLR cameras";
    end if
    %>

    Here is the error I am getting

    Compiler Error Message: CS1002: ; expected

    Source Error:

    Line 33: <%
    Line 34: if(Request("CategoryID")!="8") then
    Line 35: ptitle.text = "SLR cameras";
    Line 36: end if
    Line 37: %>


    I then want to display the value of ptitle in the title tag of the page

    eg <title>**** ptitle here *******</title>
     
    yorks45, Jan 2, 2007 IP
  7. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #7
    <%
    if request("CategoryID")<>"8" then
    ptitle = "SLR cameras"
    end if
    %>
    
    Code (markup):
    
    Line 39: <html>
    Line 40: <head>
    Line 41: <title><%=ptitle%></title>
    Line 42: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    Code (markup):
    This must be work.
     
    YIAM, Jan 2, 2007 IP
  8. yorks45

    yorks45 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    still doesnt work..get the following error

    Compiler Error Message: CS1003: Syntax error, '(' expected - line 34

    Source Error:

    Line 32:
    Line 33: <%
    Line 34: if request("CategoryID")<>"8" then
    Line 35: ptitle = "SLR cameras"
    Line 36: end if
     
    yorks45, Jan 2, 2007 IP
  9. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #9
    .Text ... With a capital T

    If you use C# to program, it's case sensitive ... ;-)
     
    kajakske, Jan 2, 2007 IP
  10. yorks45

    yorks45 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Still having problems with this...if anyone can provide assistance if sorting this small problem via messenger / yahoo / icq out I'd be happy to pay :)
     
    yorks45, Jan 4, 2007 IP