Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP .net Label and javacript href link visible

Posted on 2014-12-15
6
401 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

791 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