I have 2 buttons which I want to hide by default on page load. On click of any row in the grid, I want these buttons to be visible. How can I hide the buttons using JQuery?
RadButton lnkAdd = new RadButton();
lnkAdd.ID = "BtnEdit";
lnkAdd.Text = "Edit";
container.Controls.Add(lnkAdd);
container.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "hideButtons",
"\n<script type=\"text/javascript\">"
//+ "\n$(function(){"
+ "\n$(document).ready(function{"
+ "\n $(\"#" + lnkAdd + "\").hide(); "
+ "\n return false;"
+ "\n });"
+ "\n</script>"
);
The following script is generated:
<SCRIPT type="text/javascript">
$(document).ready(function ruchi(){
$("#Telerik.Web.UI.RadButton").hide();
return false;
});
</SCRIPT>
But the buttons do not hide!
Shouldn't it be + "\n $(\"#" + lnkAdd.ClientID + "\").hide(); "
Right now it looks like you are just passing it the fully qualified name of the type and not the actual ID.
Related
In my C# web application, I have one page with a panel control:
ViewTask.aspx
<asp:Panel ID="panelImageThumbnails" runat="server" Style="width: 100%;">
This panel gets filled using jQuery .load with page ThumbnailPanel.aspx
<script type="text/javascript">
$(window).load(function () {
LoadThumbnails();
});
function LoadThumbnails() {
$("#panelImageThumbnails").empty();
var imglink = "<span style='text-align: center; align-content:center'>Getting thumbnails, please wait!<br><br><img src='Images/loader.gif'><br><br></span>";
$("#panelImageThumbnails").append(imglink);
$('#panelImageThumbnails').load('ThumbnailPanel.aspx').hide().fadeIn(1000);
return false;
}
</script>
Inside ThumbnailPanel.aspx, I query a table for a list of images and then loop over the DataTable and write them each to another panel each as ImageButtons
//Add a new image button to the thumbnail panel
ImageButton newImageButton = new ImageButton();
newImageButton.ID = "ib_" + row["Screenshot_ID"].ToString();
newImageButton.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes);
newImageButton.PostBackUrl = "ViewImage.aspx?fileName=" + row["Screenshot_ID"].ToString() + ".png";
newImageButton.OnClientClick = "target='_blank'";
newImageButton.CssClass = "thumbnailButton";
newImageButton.ToolTip = row["Screenshot_Created"].ToString() + "(" + row["Screenshot_CreatedBy"].ToString() + ")";
newImageButton.AlternateText = row["Screenshot_Title"].ToString();
panelUploadedImageThumbnails.Controls.Add(new LiteralControl("<table border='1' style='border-collapse: collapse;' class='inlineTable'><tr><td style='font-size:7pt;'>" + row["Screenshot_Title"].ToString() + "</td></tr><tr><td>"));
panelUploadedImageThumbnails.Controls.Add(newImageButton);
panelUploadedImageThumbnails.Controls.Add(new LiteralControl("</td></tr></table>"));
I set the PostBackUrl to page "ViewImage" and feed in the Screenshot_ID. This page converts the image to a bytearray and prints it to the screen.
ThumbnailPanel.aspx works perfectly on its own. But when it's loaded into panelImageThumbnails during the jQuery .load inside ViewTask.aspx all of the hyperlinks point to ThumbnailPanel.aspx instead of ViewImage.aspx.
Any idea how I can fix my desired PostBackUrl from being ignored?
I have an image button on my form which opens a modal popup dialog on click. The onmouseout, onmouseover, onfocus, onblur events are set in the skin file.
What I want to achieve is, when the modal popup dialog is open the 'image button' image should be like it is on onmouseover and onfocus image set in the skin.
But I am not able to achieve this by adding the following js i.e.
$("#btnAdd").src=window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_on.png';
(The above js I have written in the js function which opens up the modal dialog)
since, on the fire of onblur/onmouseout event which happens since the focus shifts to the modal dialog, the image set due to above js is lost.
What can be the possible solution for this? Please inform me since I need to integrate this asap.
skin file :
<asp:ImageButton SkinId="Add" alt="Add" runat="server" ImageUrl="~/Images/Add_item_over.png"
onmouseout="this.src=window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_over.png';"
onmouseover="this.src=window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_on.png';"
onfocus="this.src=window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_on.png';"
onblur="this.src=window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_over.png';"/>
You can't access to the property src of a jQuery element.
If you wan't access to the HTMLDOMElement, you need to write $('#btnAdd')[0].
Moreover, if your btnAdd is an <button> tag, you need to do something like:
$("#btnAdd").css({
backgroundImage: url(window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_on.png';)
});
In case of an img tag
$("#btnAdd").attr('src', window.location.protocol + '//' + window.location.host + '/' + 'ClientWeb/Images/Add_item_on.png');
At a certain point i have a dynamicly generated string with html in my code-behind.
I want to open a popup with has that html as its source.
I have tried the following:
I created this method on my .aspx site (Javascript):
function OpenWindowWithHtml(html, title) {
var myWindow = window.open('', title);
myWindow.document.write(html);
myWindow.focus();
}
And in the code-behind i have this:
Response.Write("OpenPopupWithHtml(\"" + html + "\", \"" + title + "\");");
But when i try to execute this i get an error.
Does anybody see, what i do wrong here?
Or does somebody know a better way to do this?
EDIT
on button click it shoudl be like this
protected void btnAbct_Click(object sender, EventArgs e) {
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "OpenPopupWithHtml('" + html + "', '" + title + "');");
}
To execute the code ie. function you written in javascript
ClientScript.RegisterStartupScript(this.GetType(),
"newWindow", "OpenPopupWithHtml('" + html + "', '" + title + "');");
you can register client script like this
if (!ClientScript.IsClientScriptBlockRegistered("exampleScript"))
ClientScript.RegisterStartupScript(this.GetType(), "exampleScript","
<script language = "'javascript'">
alert('you just registered the start up script')
</script>
");
from the code behind file of asp.net
To Open pop-Up window , just replace this line in above code
ClientScript.RegisterStartupScript(this.GetType(),
"newWindow", String.Format("<script>window.open('{0}');</script>",
"mypage.html"));
Check this for detail : Register Client script in ASP.NET
I have several(inside loop) dynamically created html buttons like :
sb.Append("<input type=\"button\" name=\"deleteimage" + id
+ " \" id=\"btndelete" + id
+ "\" value=\"Delete\" class=\"t-button t-grid-delete\" "
+ " style=\"margin-left:10px;\" />");
and I want to get the id of the button on which I click using jquery
Help Me
Thanks
delegate using .on()(jQuery 1.7+) or .delegate()(jQuery 1.6 and lower)
$('body').on('click','input[type=button]',function(){
alert(this.id); // <-- this refers to current clicked input button
});
or
$('body').delegate('input[type=button]','click',function(){
alert(this.id);
});
Or whatever your sb element is replace body with that since it exists on dom load
How about
$('input:button').click(function(){
alert('Clicked ' + this.id);
Try this
$("input[type=button]").click(function()
{
alert(this.id);
});
You can try the following:
$(document).click(function(event) {
var target = event.target;
if ($(target).hasClass("t-grid-delete")) { // check if element has class t-grid-delete is your button
var targetId = $(target).attr("id");
// set your image id with attribute like image_id
// it take easy to get image id $(target).attr("image_id")
}
});
Use 'live' event for dynamically generated html element's event
$("input[type=button]").live('click',function()
{
alert(this.id);
});
I have the following c# code that creates image buttons which should call the javaScript method below
var imageButton = new ImageButton();
imageButton.ImageUrl = "Styles/unClicked.png";
imageButton.ID = "btn" + questionName;
imageButton.OnClientClick = "buttonPressed('" + questionName + "')";
Its outputting & # 3 9; instead of the ' in the html code and there for is causing an error (Ive had to add spaces tp prevent SO changing it to a comma)
onclick="buttonPressed('question0')
how to I prevent this?
Please try this one HtmlString (not working).
imageButton.OnClientClick = new HtmlString("buttonPressed('" + questionName + "')");
If it will not work, than you will need to create custom control or use javascript (JQuery) to add handler for click event.
<script>
$("<%=imageButton.ID%>").click(function() {
buttonPressed('<%=questionName%>');
})
</script>
The OnClientClick attribute is very limiting. Not totally sure this will work, but I have use similar code before to handle ghost text in textboxes...
imageButton.Attributes.Add("onclick", "buttonPressed('" + val + "')");
The attribute should not be HTML encoded.