I have a quick question...I have a masterpage and is there anyway that I can target the contentarea without having to use hyper links? I have tried using buttons and link buttons but it never worked. The reason why is because I want to have button states and I'm not sure how to go about doing this.
I have added an image to the link
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Tabbet.aspx"ImageUrl="~/Icons/Icon_english_a.png">HyperLink</asp:HyperLink>
and my code behind to try and show any state
void btn()
{
HyperLink1.Attributes.Add("onmousedown", "src='Images/logo.png'");
}
when I click on the image, the image is not changing to a down state.
Thanks
yes I have solution you should try following way:
<script src="Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#<%=Hyperlink1.ClientID%> img").hover(function () {
$(this).attr("src", "/Images/logo.png");
}, function () {
$(this).attr("src", "/Icons/Icon_english_a.png");
}).mousedown(function () {
$(this).attr("src", "/Images/logo.png");
}).mouseup(function () {
$(this).attr("src", "/Icons/Icon_english_a.png");
});
});
</script>
Related
I'd like to have a certain event handler to work when I press my ImageButton control by the right mouse button. How can I achieve this? I use asp.net.
You must use client side technique to catch it, for example js/Jquery. Something like
<script type="text/javascript"> $(function () { $("#ImageButton").mousedown(function (e) {
if (e.which == "3") {
// Do magic.
} }) }); </script>
My question is how can I Activate or InActivate users by clicking the button. If I clicked InActivate, the text on the button should be changed to Activate. I searched on google but I didn't get the solution:
This is Example Code For Asp.net C# code
<asp:LinkButton ID="lbtnStatus" runat="server" CommandArgument='<%#Eval("ModuleID") %>'
CssClass="imagelink" OnClick="lbtnStatus_Click"><span class='label <%#Eval("Status").ToString()=="Y"?"label-success":"label-danger"%>'><%#Eval("Status").ToString()=="Y"?"Active":"Inactive"%></span></asp:LinkButton>
How can I change the c# code to MVC Code any Idea?
You should perform it in client side. Try something like that;
$("#lbtnStatus").click(function() {
var value = $("#lbtnStatus span").text();
if(value == "Inactive")
{
$(this).html("<span class='label-success'>Active</span>");
} else if(value == "Active")
{
$(this).html("<span class='label-danger'>Inactive</span>");
}
});
You can use the following way in client side with the help of jQuery.
<button type="button" id="lbtnStatus"><span class="label-success">Active</span></button>
<script type="text/javascript">
$(document).ready(function () {
$('#lbtnStatus').click(function () {
if ($(this).find('span').hasClass("label-success"))
$(this).find('span').removeClass("label-success").addClass("label-danger").text("InActive");
else
$(this).find('span').removeClass("label-danger").addClass("label-success").text("Active");
});
});
</script>
How can I get selected text from drop-down list? Before crucifying me for asking a duplicate, I have read:
Get selected text from a drop-down list (select box) using jQuery and
Get selected text from a drop-down list (select box) using jQuery and tried the following code variations from these pages:
<asp:DropDownList ID="DDLSuburb" runat="server">
</asp:DropDownList>
alert($get("[id*='DDLsuburb'] :selected"));
alert($("[id*='DDLsuburb'] :selected"));
alert($get("#DDLsuburb option:selected"));
alert($get("DDLsuburb option:selected"));
alert($get("#DDLsuburb :selected").text());
alert($get("DDLsuburb :selected").text());
alert($get("DDLSuburb", Text));
alert($get(DDLSuburb, Text).toString());
alert($get("DDLSuburb", Text).toString());
alert($get("DDLSuburb").html());
alert($get("DDLSuburb :selected").html());
alert($get("DDLSuburb option:selected").html());
alert($get(DDLSuburb).textContent());
alert($get(DDLSuburb).innerHTML());
alert($get(DDLSuburb).innerHTML.toString());
alert($get("DDLSuburb").text());
alert($get("DDLSuburb").valueOf("DDLSuburb"));
alert($get("DDLSuburb").valueOf());
Notes: 1. I am using alert for troubleshooting. 2. I know the first part should be ($get("DDLSuburb"), as opposed to the options without quotes. Visual Studio 2015, ASP.net.
Edit: Trying to raise the alert via button click:
<input type="button" value="Get Postcode" onclick="onClick()" />
<script type="text/javascript">
var onClick = function () {
alert($get("DDLSuburb")...);
}
Try
<script type="text/javascript">
$(document).ready(function () {
$("#<%=DDLSuburb.ClientID %>").change(function (e) {
alert($("#<%=DDLSuburb.ClientID %> option:selected").text());
});
});
</script>
The reason <%=DDLSuburb.ClientID %> is used is because in the HTML the ID DDLSuburb is translated into something like ctl00$mainContentPane$DDLSuburb to ensure unique ID's on the page. That's why your JavaScript cannot find it.
Or you can use the property ClientIDMode="Static" in the DropDown to keep the ID name the same in the HTML, but I do not recommend this.
this code use for show selected item by using jQuery. ddlItem is a id of dropdownlist.
<script>
$(document).ready(function () {
$("#ddlItem").change(function () {
var ddlItem = document.getElementById("<%= ddlItem.ClientID %>");
var selectedText1= ddlItem.options[ddlItem.selectedIndex].innerHTML;
alert("You selected :" + selectedText1);
});
});
</script>
I have an issue in implementing the JQuery dialog with asp.net form. When I click on #hlChangePassword nothing happens. This is my code below:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#hlChangePassword').click(function () {
var dlg = jQuery('div#ChangePass').dialog({
width: 500,
height: 500,
modal: true,
buttons: {},
open: function (event, ui) {
$(".ui-dialog-titlebar-close").hide();
}
});
dlg.parent().appendTo(jQuery("form:first"));
});
});
</script>
html
<asp:HyperLink ID="hlChangePassword"
runat="server" NavigateUrl="#">Change Password</asp:HyperLink>
<div id="ChangePass" style="display:none;">
//The content
</div>
I don't know what is the problem. Please help me.
User event.preventDefault(); to prevent the post back as follows
jQuery(document).ready(function () {
jQuery('#hlChangePassword').click(function (event) {
var dlg = jQuery('div#ChangePass').dialog({
width: 500,
height: 500,
modal: true,
buttons: {},
open: function (event, ui) {
$(".ui-dialog-titlebar-close").hide();
}
});
dlg.parent().appendTo(jQuery("form:first"));
event.preventDefault();
});
});
As hlChangePassword is a server control so it will post back. to overcome this you should use event.preventDefault.
Also you are using id selector which can change at run-time due to master page or user-control. So use server id or static id for the link as follows if you are using asp.net 4.0 or above as follows
ClientIDMode="Static"
<asp:HyperLink ID="hlChangePassword" ClientIDMode="Static"
runat="server" NavigateUrl="#">Change Password</asp:HyperLink>
Bingo...
script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js">
add above line it wont work without ui.js.
I have a LinkButton that I need to perform a click on to cause a postback. The actual link target is:
javascript:__doPostBack('ctl00$c1$btnRefreshGrid','');
Clicking the link does perform the postback, as verified by a breakpoint in the code-behind. Also pasting javascript:__doPostBack('ctl00$c1$btnRefreshGrid','') in the address bar of the browser works with the same effect.
I've tried the following with no effect at all:
__doPostBack('ctl00$c1$btnRefreshGrid','');
$('#ctl00$c1$btnRefreshGrid').click();
$('#ctl00$c1$btnRefreshGrid').trigger('click');
eval($('#ctl00$c1$btnRefreshGrid').attr("href"));
I've tried using both <%= btnRefreshGrid.UniqueID %> and <%= btnRefreshGrid.ClientID %> to generate the selector.
You were close, this works in Firefox:
function clickMyButton() {
javascript:__doPostBack('<%= MYBUTTONID.UniqueID %>','')
};
the following works for the following anchor (originally asp:LinkButton in server side) inside li
<li>
<a id="ctl00_ContentPlaceHolder1_ChangeNumberItemGrd_ctl01_FindByID" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ChangeNumberItemGrd$ctl01$FindByID','')">287573</a>
</li>
because i do not have the name i must generate it from it
$(".msglist li").on("click", function () {
var postbackArg = $(this).find("a").prop("id").replace(/_/g,"$");
__doPostBack(postbackArg, '');
});
$("#<%= btnRefreshGrid.ClientID %>").click();
Should work...
Hope it helps!!!
In firebug you can get the correct name and link action of the link button:
<a id="MainContent_ctl00_Submit_Button" href="javascript:__doPostBack('ctl00$MainContent$ctl00$Submit_Button','')"></a>
var Eventtarget = $("#btnSave").attr("name");
__doPostBack(Eventtarget, "");
ASP.NET:
<asp:LinkButton ID="btnDelete" runat="server" CssClass="btn-u btn-u-xs btn-u-red"
OnClientClick="return get_confirm(this,event);"> <i class='fa fa-trash-o'> Delete </i> </asp:LinkButton>
JavaScript:
function get_confirm(obj, e) {
e.preventDefault()
var postbackArg = obj.href.replace("javascript:__doPostBack('", "").replace("','')", "");
$.confirm({
title: 'Confirm',
content: 'Are you sure to delete this item?',
closeIcon: true,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-red',
action: function () {
__doPostBack(postbackArg, '');
}
},
cancel: {
text: 'Cancel',
action: function () {
}
}
}
});
}