Solved

ASP .net Label and javacript href link visible

Posted on 2014-12-15
6
380 Views
Last Modified: 2014-12-17
Hi Expert,

I have two Label in aspx page, and I want them visible by contidtion

<asp:Label ID ="lb1" runat = "server" Text = "Complete a <a href='javascript:openForm(1);'>Information change form</a> if any details about your information changed." />

<asp:label ID = "lb2" runat = "server" Text="If this information incorrect, please update:"></asp:label><asp:LinkButton ID="lnkInfo" runat="server"
                    href="javascript:customConfirm(‘Are you sure you want to exit this screen?','../UpdateInfo/Update.aspx', null, true)"
                    Text="Update Account Information"></asp:LinkButton>

In code behind page

If ABC is true then
lb1.visible = true
lb2.visible=false
else
lb1.visible = false
lb2.visible=true
end if

lb1 work correctly and lb2 always visible.

How I can make lb2 work?

Thanks in advance.
0
Comment
Question by:dshi15
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:Ammar Gaffar
Comment Utility
Hi dshi15,

The code you submitted must work unless your condition if ABC = true is always return false. You need to check this condition output first, you can place break point in your first line if ABC=true and then press F10 to see what is next step.

Or you can make both label visibly to false as default and run your code, if it is showing label 1 in all cases then for sure the issue in your condition.
<asp:Label ID ="lb1" runat = "server" Text = "Complete a <a href='javascript:openForm(1);'>Information change form</a> if any details about your information changed."  visible="false" />

<asp:label ID = "lb2" runat = "server" Text="If this information incorrect, please update:" visible="false"></asp:label><asp:LinkButton ID="lnkInfo" runat="server"
                    href="javascript:customConfirm(‘Are you sure you want to exit this screen?','../UpdateInfo/Update.aspx', null, true)"
                    Text="Update Account Information"></asp:LinkButton>

Open in new window



Good Luck
0
 
LVL 1

Author Comment

by:dshi15
Comment Utility
Hi Expert,

I tested contition it works fine. lb1 can change visible true or false based on condition, but lb2 always visible and I checked an online article and it said href link need be inside Label. This is exactly lb1 did, now i need change label2 same way, remove linkbutton and add href link inside Label2 tag, I just don't know how to do it. Because there are several single quote invovled.

Thank you.
0
 
LVL 12

Expert Comment

by:Ammar Gaffar
Comment Utility
Hi,
Just hide your linlbutton (lnkInfo ) as well

If ABC is true then
lb1.visible = true 
lb2.visible=false
lnkInfo.visible = false
else
lb1.visible = false
lb2.visible=true
lnkInfo.visible = true
end if

Open in new window

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:dshi15
Comment Utility
Yes, it is exactly I did, but Label2 and lnkInfo always visible. So I need remove a link button and add  href inside Label2 I guess.
0
 
LVL 12

Accepted Solution

by:
Ammar Gaffar earned 500 total points
Comment Utility
Hi,
You are using link button, and there is no href property for the link button.
Anyway, you can use div (run at server) as a container for your label and link button see code block bellow:
<div id="myDiv" runat ="server" visible ="false">
<asp:label ID = "lb2" runat = "server" Text="If this information incorrect, please update:"></asp:label><asp:LinkButton ID="lnkInfo" runat="server"
                    href="javascript:customConfirm(‘Are you sure you want to exit this screen?','../UpdateInfo/Update.aspx', null, true)"
                    Text="Update Account Information"></asp:LinkButton>
</div>

Open in new window


And in you code:
If ABC is true then
lb1.visible = true 
myDiv.visible = false
else
lb1.visible = false
myDiv.visible = true
end if

Open in new window


Good Luck
0
 
LVL 1

Author Closing Comment

by:dshi15
Comment Utility
Thank you very much and I found the usercontrol in the page which have Label2 visible with no condition and so sorry about that.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now