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
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"
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:
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>
<% 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.
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
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