Solved

ASP .net Label and javacript href link visible

Posted on 2014-12-15
6
419 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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…

739 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