Display notes when hovering over ASP.NET buttons - c#

I have a number of buttons on my page and I would like to have some kind of notes appearing next to it explaining what the button is for when they hover over any particular button.
How would I go about achieving that?
(I am after something similar to when you hover over the tags below on this stackoverflow page...)

You should do like this
<form runat="server">
<asp:Button id="button1" Text="Submit" runat="server"
ToolTip="This is an example-button"/>
</form>
Here tooltip shows your message.

Tap into the hover of that item using jQuery: http://api.jquery.com/hover/
Attach a function to hover that shows and hides a div. There are many examples of showing popup windows using jQuery. A quick Google search took me Here. You will also have to position the popup in the correct location. You can get the correct location using jQuery as well. http://api.jquery.com/position/

If you prefer using codeBehind, try this:
nameOfControlButton.ToolTip = "Here is my tooltip comment";

Related

How would I let 1 .aspx page use another .aspx page's code?

I have 2 aspx files in my project. The first.aspx page has some content on it and when I click on a button, it will launch a frame (second.aspx that only has code to show a calendar) on the same page.
Now once that calendar(second.aspx) loads on first.aspx, I want to click a link on the calendar that will .show() a hidden DIV on the first.aspx page.
How do I access code cross pages? In other words, how can I write some code in second.aspx that will affect first.aspx.
What you're asking for is not really possible. You're probably approaching it the wrong way. What you should do is turn your calendar page into a user control so that it can be used seamlessly in first.aspx.
Here is how to get started with user controls in asp.net:
After you turn it into a user control there are different approaches to getting access to the properties of the user control from your page. Here is one approach using the FindControl method.
Hope that helps.
The easiest solution would be to show and hide your div with jquery. Simple give your div a class like:
<div class="myCalendarDiv" style="display:none" />
And your Button should look like this:
<asp:Button id="myButton" OnClientClick="return ShowCalendar();" runat="server" />
<script type="text/javascript">
function ShowCalendar() {
$(".myCalendarDiv").show();
return false;
}
</script>
Another way would be instead of creating a seprate webpage for the calendar, as proposed you can use a jquery dialog, or make a usercontrol and embedd it on the same page.
(Posted on behalf of the OP).
So since I was dealing with an Iframe, I found out that you can target the parent window which would be first.aspx.
I used "window.parent.MYFUNCTION();" to call my JavaScript function on first.aspx and show the div.

Update input type=text value or textbox control resize event

I have been having trouble updating the value for my input type=text or the texbox control text value with the jquery $(window).resize(function(){}); I know that the event fires because when i resize the browser an alert will appear. I also am using the functionality for something else.
It currently looks like this:
$(window).resize(function(){
if($(window).width()>1080){
var innerwidth = $(window).width()-170;
$("#div1").width(innerwidth);
}
I want to add this:
$(window).resize(function(){
if($(window).height()>500){
var innerheight = $(window).height();
$('input.hiddentest').val(innerheight);
}
I know that the issue lies with:
$('input.hiddentest').val(innerheight);
I have also tried this:
$('#texttest.ClientID').text(innerheight);
This is the input and the textbox below that I am using(note that the type used to be hidden, but i dont think that makes an issue and I wanted it to be visible for debugging purposes)
<input id="hiddentest" type="text" visible="true" name="hiddentest" onclick="test();" runat="server" value="1000" />
<asp:TextBox id="texttest" Visible="true" runat="server" Text="1000" />
Overall I have been looking for a way to dynamically update the values as the page resizes with the size of the page. My geuss is that i am not using the right thing to identify the id's. Thanks for taking the time to look at this and for any replies.
P.S. I am also open to the idea of using a javascript function instead but i can't even seem to get the function to fire for the resize event so it would require more help.
This is what i have so far:
window.onresize=Test();
function Test(){
var hdnfld= document.getElementById("texttest");
var testing = window.innerWidth;
alert(testing);
hdnfld.text= testing;
}
Use just ID of elements without dots (that actually represent the classes you don't have).
So use
$('#hiddentest').val(innerheight)
and
$('#texttest').val(innerheight)
Note that asp:TextBox renders as inptut type="text" so you still have to use .val() on it, not .text()
Hidden text box id is "hiddentest" so the code will be
$('#hiddentest').val(innerheight);
hiddentest is an id not a class in your case
Try,
$(window).resize(function(){
if($(window).height()>500){
var innerheight = $(window).height();
$('#hiddentest').val(innerheight);
}
});
<asp:TextBox id="texttest" Visible="true" runat="server" Text="1000" />
For the above asp.net textbox control, the ID changes dynamically when rendered (prepended with master and page information), id looks similar to main_ctrl100_texttest
var hdnfld= document.getElementById("texttest");, so this no longer holds good. Use a class instead.
<asp:TextBox id="texttest" Visible="true" runat="server" CssClass="texttest" Text="1000" />
var hdnfld = document.getElementsByClassName("texttest");
If you need more info on how to access .net controls using jquery, see here.

How to disable a link tag to open fancybox mentioned in href url?

In a ASP.NET Web Application, facnybox of jQuery is used on button click.
As mentioned in link: http://fancybox.net/howto
<a id="lnkEmail" href="../Email/Default.aspx" runat="server">
<div id="DivBtnEmail" class="button" runat="server">
<asp:ImageButton ID="BtnEmail" ToolTip="Send Email" CssClass="image" ImageUrl="../img/tlb_list_email.gif" OnClick="BtnEmail_Click" runat="server" />
</div>
</a>
In some cases during application, there is a need to disable the buttons which opens fancybox.
I used asp:button property to disable the button.
BtnEmail.Enabled= false;
But, due to link tag it still works and open the url mention in link href in a fancybox.
How to disable a link tag to open a fancybox ?
I've tried the solution mention in link : how to disable link in jquery
But, it didn't work for me.
Any help ???
Try this:
$('#<%= BtnEmail.ClientID %>').prop('disabled', true);
You can call a return false; That way, JS doesnt return the event handler.
$('#lnkEmail').click(function() {
if (conditions) return false;
// else do your stuff
});
You should use some kind of selector for fancy box that allows you to be more flexible.
If you’re selecting html elements where fancybox will be applied using class then you can create another identical class but named differently and then use that.
This doesn’t require additional javascript but it will require additional CSS definitions.
Above discussion helps me to figure it out how to disable the link tag. I disable the link tag from server side where I was enabling/disabling the other buttons w.r.t conditions.
It was the "Disabled" property which needs to be updated accordingly.
this.lnkEmail.Disabled = true;

About modal pop control to the ajax control tool kit

First of all hi too member
now my 1st talk i had one ajax control tool kit tht doesnt work on the vs 2008
so please help me for tht and
other problem I had make one modal pop code for the site but it nt working properly
mean when I click on the button it will only display Loader image but it did nt display tht page or div tag which cover the whole page with black color
so i need that back ground color div tag
Some please help me
I am badly stuck with this problem
in advance thank you
If I have deciphered your post correctly, you can show the ModalDialog but it doesn't "color" the rest of the page, therefore making the popup non-Modal?
If this is the case, then you need set the BackgroundCssClass attribute of the ModalPopupExtender to a valid CSS class.
I normally use this...
.ModalBackground
{
background-color:Gray;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="ModalBackground" [... the rest of the attributes....] />

asp: LoginStatus control as a button, not text

I'm pretty new to this, infact this is my first post.
I'm using Visual Studio 2005. On my .aspx page, I have a 'loginStatus' control so the user can logout of a page which works well. However the 'loginStatus' control is not a button, it's text ("logout"). Is it possible to make this into a button?
Here is the line of code:
<asp:LoginStatus ID="LoginStatus1" runat="server" OnLoggingOut="LoginStatus1_LoggingOut" />
Would I just add some style somehow? If so, please help me.
Thanks.
Haven't tested this, but it might solve your problem : forum post
Otherwise you might use jQuery to solve this. (I think...)
You can try this:
<asp:LoginStatus ID="HeadLoginStatus" runat="server"
LogoutAction="Redirect"
LogoutText="<input type='button' value='Log Out' />"
LogoutPageUrl="~/"/>
The LogoutText attribute contains the definition of a simple button, that you can customize with css and js.
Just use LoginImageUrl or LogoutImageUrl
<asp:LoginStatus runat="server"
LogoutImageUrl="~/App_Themes/Theme1/Images/logout.png"
LoginImageUrl="~/App_Themes/Theme1/Images/login.png" />
Using JavaScript:
Grab the url of the link and add a button which, when onclick'ed, points the browser to that url. Then add display:none to the original link with CSS.
You can also use an image as Colin says, but that would fake a button and I assume you want a real button.
YOu could try to render it using an Image, as stated here
The LoginStatus control displays either a text or an image link, depending on the setting of the LoginImageUrl and LogoutImageUrl properties. You can display either text or images for one or both states.
Cheers, I will have a look into this :)
I think it's strange that the option of turning it into a button is not already available.
You could wrap the LoginStatus inside of a LinkButton (Or any kind of button).
<asp:LinkButton id="LinkButton1" runat="server">
<asp:LoginStatus id="LoginStatus1" runat="server" />
</asp:LinkButton>
then use the LinkButton1 events.
You could always just extend the LoginStatus control by creating a derived class, and overriding the rendering behaviour to change the output elements into your desired elements, or add style attributes, or whatever.
(apologies for VB)
Public Class MyLoginStatus
Inherits System.Web.UI.WebControls.LoginStatus
Public Overrides Sub RenderBeginTag(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.AddStyleAttribute("display", "none")
MyBase.RenderBeginTag(writer)
End Sub
End Class
This kind of behaviour could be extended to turn the output into a button, if you so wish, either in aggregate (modifying the final rendered output by creating your own HtmlTextWriter enclosing a StringWriter and invoking the base methods), or by injecting your own behaviour into the relevant render events.
Have you looked into Control Adapters - this allows you to alter the HTML generated. It's primarily used for adapting HTML for different browsers and devices, but can be used to have complete control over server controls.
Lee
I know this is an old post but I'll chime in.
Here's a very simple way to make a button out of the LoginStatus control. Set the control CssClass to a bootstrap button and your good to go. Whatever text you have for the login and logout will go into the button.
<asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="btn btn-primary" LogoutPageUrl="yourlogin.aspx" />
http://www.w3schools.com/bootstrap/bootstrap_buttons.asp

Categories

Resources