Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a property in my C# file which I use to update the Text of my Headers. I also, placed this in my HREF to update my links however it does not update them. I initially thought the Page_Load event was not firing before this property was updated but not sure. I placed <%=this.Discipline %> in my HREF and it does not update, yet it updates the text. Please help!


Here is my property Discipline which i set based on the ?QueryString:

C#
public string Discipline
		{
			get;
			set;
		}



Here is the Page_Load event where I update my Discipline

C#
/// <summary>
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">The EventArgs for this event.</param>
protected void Page_Load(object sender, EventArgs e)
{
	if(Request.QueryString.Count > 0)
	{
		foreach(string key in Request.QueryString.AllKeys)
		{
			string value = Request.QueryString[key];

			if(!string.IsNullOrEmpty(value))
			{
				if(key.ToLower() == "discipline")
				{
					if(value == "Cardiology")
					{
						this.Discipline = "Cardiology";
					}
					if(value == "Chiropractic")
					{
						this.Discipline = "Chiropractic";
					}
					if(value == "Dermatology")
					{
						this.Discipline = "Dermatology";
					}
					if(value == "Family")
					{
						this.Discipline = "Family";
					}
					if(value == "Internal")
					{
                                                this.Discipline = "Internal";
					}
					if(value == "Urgent")
					{
						this.Discipline = "Urgent Care";
					}
					
				}
                        }
                 }
          }
}



Here is my atag where the HREF does not update and the H1 tag does.

ASP.NET
                                <a  runat="server" id="a_Overview" class="ContentSideBar" style="vertical-align: middle;" href="/Products/Specialty.aspx?discipline=<%=this.Discipline %>&content=Overview">
                                   <img  runat="server" id="img_Overview" class="MenuIcons" src="/Images/Icons/Categoryblue.png" alt="Specialty" />
                                   <span  runat="server" id="span_Overview" class="MenuHeader">Specialty Overview</span>
                                   <img  runat="server" id="arrow_Overview" class="MenuArrow" alt="menuArrow" src="/Images/Icons/RightArrowwhite.png" />
                               </a>


<h1 class="SpecialtyHeader"><%=this.Discipline %>
               <span class="SpecialtyHeader">EHR</span>
               <%--<span class="SpecialtySubHeader">Electronic Health Record</span>--%>
           </h1>
Posted
Comments
ZurdoDev 25-Nov-13 14:38pm    
Do it in C#
andrewster05 25-Nov-13 15:15pm    
I can change it in C# but that means I have to reference 30 links on several pages to updated manually vs. just setting this dynamically. I want to know if this just doesn't work in HREF? It is working in the text.
ZurdoDev 25-Nov-13 15:36pm    
I think it does but if I recall you have to use EVAL and concatenate your strings together. It seems like I did it years ago but don't quite recall. That's why when I have issues like this I just do it in C#, much easier. :)
footballpardeep 25-Nov-13 15:13pm    
Use Hyperlink

Hi dude,
Try like this..

XML
<div id="divContainer" runat="server">



            <asp:HyperLink ID="aa1" runat="server" Text="asp tag" NavigateUrl="<%# this.Discipline %>">
            </asp:HyperLink>
            <br />

            <h1 class="SpecialtyHeader"><%=this.Discipline %>
                <span class="SpecialtyHeader">EHR</span>
                <%--<span class="SpecialtySubHeader">Electronic Health Record</span>--%>
            </h1>
            <br />

            <a runat="server" id="a_Overview" class="ContentSideBar" style="vertical-align: middle;" href='<%# string.Format("/Products/Specialty.aspx?discipline={0}&content=Overview", this.Discipline) %>'>
                <img runat="server" id="img_Overview" class="MenuIcons" src="/Images/Icons/Categoryblue.png" alt="Specialty" />
                <span runat="server" id="span_Overview" class="MenuHeader">Specialty Overview</span>
                <img runat="server" id="arrow_Overview" class="MenuArrow" alt="menuArrow" src="/Images/Icons/RightArrowwhite.png" />
            </a>


            <br />
            <br />
            <asp:HyperLink ID="HyperLink1" runat="server" Text="last tag" NavigateUrl='<%# string.Format("testinglink.aspx?query={0}", this.Discipline) %>'>


            </asp:HyperLink>

        </div>






C#
public string Discipline
       {
           get;
           set;
       }

       protected void Page_Load(object sender, EventArgs e)
       {
           if (Page.IsPostBack) { }
           else
           {
               Discipline = "Cardiology";
               divContainer.DataBind();

           }
       }





Note:
What you have to do is, u have to place all the controls in a container control
and after setting the desired property in cs file. you have to bind the container control by calling databind function
C#
divContainer.DataBind();


you can check the code for formatting the url to frame the query strings
 
Share this answer
 
Comments
andrewster05 26-Nov-13 9:19am    
Thanks for this. I just used your binding example for my a tag and labeled my divContainer. then called the DataBind() after I set my Discipline in C#. THANKS! AGAIN

href='<%# string.Format("/Products/Specialty.aspx?discipline={0}&content=Charting", this.Discipline) %>'

divConatiner.DataBind();
Karthik_Mahalingam 26-Nov-13 10:07am    
andrew,
because of your issue, i have learned a new stuff today . thanks :)
You may refer to the question below. It suggested enclosing the whole attribute in a <% %> and then do the necessary concatenation.

http://stackoverflow.com/questions/3434744/using-databinder-eval-in-style-attribute-of-an-asp-net-control[^]
 
Share this answer
 
add
C#
using System.Web.UI.HtmlControls; 


C#
HtmlAnchor a1 = link1;
        a1.HRef = "www.mySite.com/mypage.aspx";
 
Share this answer
 
v2
Comments
andrewster05 25-Nov-13 17:29pm    
Sorry, I know I can change the HREF manually in code. I want to understand why properties are not updated in the HREF or if I am doing this incorrectly. If I can get <%= this.Discipline %> to work in my HTML it will save alot of work effort and ongoing maintenance. Thanks,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900