Making a hyperlink inside a button in asp.net - asp.net

I have a button on my asp.net page that (upon mouseover) needs to act like a hyperlink (the hand cursor). I cannot use a linkbutton because I need the GUI of a regular asp:button.
Is there a way to create the hyperlink cursor on mouseover?
Thanks

Using css you can say:
.anchor {cursor: pointer; cursor: hand;}
and then in your aspx:
<asp:Button CssClass="anchor" ... >

Use the following for the hand cursor on button mouse over:
<asp:Button ID="Button1" runat="server" Text="Click Me" CssClass="ButtonClass" />
The in a style sheet or inline in the page itself define the class:
.ButtonClass
{
cursor: pointer; cursor: hand;
}
Use both (pointer and hand) for cross browser compatibility.

Add this into your button's markup...
style="cursor: pointer; cursor: hand;"
so...
<asp:Button id="test" text="test" runat="server" style="cursor: pointer; cursor: hand;" />

Related

remove background from radcombo box

I am using radcombobox to display data, now I am not using any css style for the radcombox, but it still has gray color background.
I want to remove that color.
Below is my rad combobox code :
<telerik:RadComboBox ID="RadCountry" runat="server" CssClass="rcbInput rcbEmptyMessage"
AutoPostBack="False" EmptyMessage="Select a Customer" EnableAutomaticLoadOnDemand="True"
ItemsPerRequest="10" ShowMoreResultsBox="True" EnableVirtualScrolling="True" Filter="Contains" DataTextField="Contact_First_Name"
Font-Names="Arial" Font-Size="11px" ShowToggleImage="false">
</telerik:RadComboBox>
I am also attaching the output of the given code.
i solve this by using below css
<style type="text/css">
div.CustomCssClass .rcbInputCell INPUT.rcbInput {
color: black;
height: 1px;
padding-top: 10px;
}
</style>
Use browser debugger and goto to Inspect Element, find which class / element is the reason for background. Then overwrite css to background:none!important for that element / css rule.

How to make a radiobutton text bold?

I have a radiobutton and want to show its text as bold.
1) I have tried with
<asp:RadioButton ID="RadioButtonLevel0" runat="server"
GroupName="ItemAccess" value="0" AutoPostBack="true"
oncheckchanged="RadioButton_CheckedChanged"
Text="Only to Me" Font-Bold="true"/>
... But it is still showing the text with normal font-weight.
2) I have tried with
<asp:RadioButton ID="RadioButtonLevel0" runat="server"
GroupName="ItemAccess" value="0" AutoPostBack="true"
oncheckchanged="RadioButton_CheckedChanged"/>
<b>Only To Me</b>
</asp:RadioButton>`
But this is producing an error.
Try out the below code snippet:
<asp:radiobutton ID="rdbText" runat="server" CssClass="bold" Text="Text"></asp:radiobutton>
<style type="text/css">
.bold
{
font-weight:bold !important;
}
Its surly because of CSS..you can also check it..install the firebug or use any developer tool to inspect the element..it will show you which css is overriding it..
I think this can slow your problem..try this.
define a css on your page in which your radio button is than apply this css on your radio button..
<style type="text/css">
.bold
{
font-weight:bold !important;
}
</style>
"!important" will override every thing..
<asp:RadioButton ID="rbtn1" runat ="server" Text ="check1" style="font-weight :bold;" />
I think it is surely because of css of parent control. check with inspect element and know which parent control is cause for this. For example if label is the cause then modify the css class as
.bold > label {
font-weight:bold !important;
}
... This will solve your problem.
use style=>font-weight for making radio button bold:
<asp:RadioButton ID="RadioButton1" runat="server" style="font-weight: 900" Text="test" />
if it doesn't work, it is because of parent CSS. if you have chrome you can use developer tools to see where exactly the Inherited CSS comes from. if you have IE you can use F12 for developer tools. Trace Syle it show you the reason
<asp:RadioButton ID="RadioButton1" GroupName="RadioButton12" runat="server" Text="test1" /><br />
<asp:RadioButton ID="RadioButton2" GroupName="RadioButton12" runat="server" Text="test2" />
<style>
input[type="radio"] + label {
font-weight: normal !important;
color: gray;
opacity: 0.5;
cursor: pointer;
}
input[type="radio"]:checked + label {
color: initial;
opacity: 1;
cursor: pointer;
}
</style>
input[type="radio"] + label {
font-weight: normal !important;
color: gray;
opacity: 0.5;
cursor: pointer;
}
input[type="radio"]:checked + label {
color: initial;
opacity: 1;
cursor: pointer;
}
<asp:RadioButton ID="RadioButton1" GroupName="mygroup" runat="server" Text="test1" /><br />
<asp:RadioButton ID="RadioButton2" GroupName="mygroup" runat="server" Text="test2" />
<span><input id="MainContent_RadioButton1" type="radio" name="ctl00$MainContent$RadioButton12" value="RadioButton1" checked="checked"><label for="MainContent_RadioButton1">Test1</label></span><br>
<span><input id="MainContent_RadioButton2" type="radio" name="ctl00$MainContent$RadioButton12" value="RadioButton2"><label for="MainContent_RadioButton2">Test2</label></span>

How to make (link)button function as hyperlink?

How do I use an asp:Button or asp:LinkButton as asp:Hyperlink?
The existing Hyperlink just goes to another section on the same page: NavigateUrl="#Section2"
I want to do this in the aspx file without additional coding. Thanks.
The purpose is to have a button look instead of the underlined text BUT I don't want to use an image with hyperlink to achieve this purpose.
You can use OnClientClick event to call a JavaScript function:
<asp:Button ID="Button1" runat="server" Text="Button" onclientclick='redirect()' />
JavaScript code:
function redirect() {
location.href = 'page.aspx';
}
But i think the best would be to style a hyperlink with css.
Example :
.button {
display: block;
height: 25px;
background: #f1f1f1;
padding: 10px;
text-align: center;
border-radius: 5px;
border: 1px solid #e1e1e2;
color: #000;
font-weight: bold;
}
There is a middle way. If you want a HTML control but you need to access it server side you can simply add the runat="server" attribute:
<a runat="server" Id="lnkBack">Back</a>
You can then alter the href server side using Attributes
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lnkBack.Attributes.Add("href", url);
}
}
resulting in:
<a id="ctl00_ctl00_mainContentPlaceHolder_contentPlaceHolder_lnkBack"
href="url.aspx">Back</a>
The best way to accomplish this is by simply adding "href" to the link button like below.
<asp:LinkButton runat="server" id="SomeLinkButton" href="url" CssClass="btn btn-primary btn-sm">Button Text</asp:LinkButton>
Using javascript, or doing this programmatically in the page_load, will work as well but is not the best way to go about doing this.
You will get this result:
<a id="MainContent_ctl00_SomeLinkButton" class="btn btn-primary btn-sm" href="url" href="javascript:__doPostBack('ctl00$MainContent$ctl00$lSomeLinkButton','')">Button Text</a>
You can also get the same results by using using a regular
.
This can be done very easily using a PostBackUrl and a regular button.
<asp:Button ID="Button1" runat="server" Text="Name of web location" PostBackUrl="web address" />
you can use linkbutton for navigating to another section in the same page by using PostBackUrl="#Section2"

Give spacing between text and radio in ASP

How can I give spacing between Radio Button and Text using Asp:RadioButton control in ASP.NET?
<asp:RadioButton ID="radio1" runat="server" GroupName="Group1" />
Try:
<asp:RadioButton ID="radio1" CssClass="Space" runat="server" GroupName="Group1" />
and CSS:
.Space label
{
margin-left: 20px;
}
works here...
Use CSS:
input[type="radio"]
{
margin-right: 2px;
}
Or:
input[type="radio"] + label
{
margin-left: 2px;
}
Another method that works is to precede the text property of the radiobutton with the symbol like this Text=" I have pad before me"
where is your text? use a label for the radiobutton or put some margin in CSS around the button.

How to add a custom cursor for a ASP.NET control?

How can I add a custom mouse cursor (say cursors from C:\Windows\Cursors directory) onto a ASP.NET user control?
Thanks a bunch,
dattebayo...
you can use the CSS cursor attribute (see this page for available cursors).
<asp:Button ID="Button1" runat="server" Text="Button" style="cursor: pointer" />
or
<style type="text/css">
.PointerCursor
{
cursor: pointer;
}
</style>
<asp:Button ID="Button1" runat="server" Text="Button" CssClass="PointerCursor" />

Resources