Solved

ASP .net Label and javacript href link visible

Posted on 2014-12-15
6
388 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
ID: 40502014
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
ID: 40503774
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
ID: 40504189
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:dshi15
ID: 40504870
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
ID: 40505012
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
ID: 40505818
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

911 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

22 Experts available now in Live!

Get 1:1 Help Now