SharePoint Javascript Popup Link inside MasterPage - javascript

In SharePoint I am trying to create a link that pops up a window
<a id="Z5" href="javascript:popUp('<% $SPUrl:~site/Pages/Mine.aspx%>')" runat="server" style="text-decoration:none;color:#000000">Mine</a>
But when I use that code i get a link with exactly javascript:popUp('<% $SPUrl:~site/Pages/Mine.aspx%>)' in my page how can I use the SPUrl and still have a javascript popup any ideas?

I ended up switched my link to
<a id="Z5" href="javascript:popUp()" runat="server" style="text-decoration:none;color:#000000">Mine</a>
Then changed my JS to
window.open("<asp:Literal runat="server" Text="<%$SPUrl:~site/pages/Mine.aspx%>" />"
and it worked.

Related

onDoubleClick asp image not working

I am working on a project and I need to be able to call a java script function when double clicking on a image. So far, for testing, I was using the On Click function and it was working perfectly, but now that I added the "Double" work it doesn't seem to work.
Please see below the code on the asp image:
<asp:Image href="#" ID="MapImage" runat="server" Height="601px" Width="469px" OnDoubleClick="javascript:MapImage_Click()"/>
This is the java script function code:
function MapImage_Click() {
alert('hello');
}
Do anyone have any idea why this is happening?
Thanks!
Use ondblclick instead of OnDoubleClick.
Correct code would be <asp:Image href="#" ID="MapImage" runat="server" Height="601px" Width="469px" ondblclick="javascript:MapImage_Click()"/>
Try ondblclick="MapImage_Click();"

ASP.NET HyperLink Eval in a Javascript function

I've added a HyperLink control to a GridView within a TemplateField and I want it to redirect the user to a specific page, passing the ID from the selected row. The following works just fine:
<asp:HyperLink ID="hlViewBasketItem" runat="server" Text="Detail"
NavigateUrl='<%# Eval("BasketItemID", "/BasketItemDetail.aspx?popUp=true&id={0}") %>'>
</asp:HyperLink>
The ID evaluates correctly; for example: "/BasketItemDetail.aspx?popUp=true&id=52"
The problem I have is that I need to make a call to a Javascript function to control the display of my page (so that it appears within a popup). I've tried the following:
<asp:HyperLink ID="hlViewBasketItem" runat="server" Text="Detail"
NavigateUrl='<%# Eval("BasketItemID", "javascript:dnnModal.show('/BasketItemDetail.aspx?bid={0}&popUp=true',false,550,950,false)") %>'>
</asp:HyperLink>
...but I'm getting a "server tag is not well formed" error.
Is there a actually a way to do this?
This was the answer:
NavigateUrl=<%# "Javascript:dnnModal.show('BasketItemDetail.aspx?popUp=true&bid=" + DataBinder.Eval(Container.DataItem, "BasketItemID").ToString() + "')"%>
I can go to bed now :)
rather than using asp.net hyperlink add use html anchor tag and call java script function as follows:
//javascript function
<script>
function openPop(drp) {
window.open('/BasketItemDetail.aspx?bid='+drp+'&popUp=true', false, 550, 950, false);
}
</script>
// Anchor tag
Click Here

How to click on an image with a hyperlink using Javascript?

The HTML of the page I wish to use for this is as follows:
<A HREF= "http://www.example.com"
TARGET="_new" status="Home Directory" title="Home Directory"
urn="Home Directory" FOLDER="http://www.example.com"><IMG align=textTop border="0" src="images/buttons/mywork.gif" alt="Select this icon to show your Home Folder" ></td>
How can I simulate a click on this hyperlinked image just using Javascript? I don't have edit privileges for this page so I need to work with what I have already got in the page (above)
You can use firebug plugin for firefox and code your javascript from the console. Google chrome also has a console.
Give it an id for a start and then invoke using "apply"
var x = document.getElementById("linky");
x.onclick.apply(x);
I would use the jQuerify plug-in. Then type $('a').click(); in the Firebug console.

Cannot call modal popup of master page in child page

I am using a modal popup for to display login box. The modal popup is in the master page and associated with a LogIn link therein. Now I want to call the same modal popup in a child page using a different link button. The modal popup can be called by the LogIn link of master page but I want to add this second control (linkButton) in child page, which can call the modalpop of master page.
I tried this in child page:
function LogIn2()
{
$find("programmaticModalPopupBehavior").show();
}
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="LogIn2">Log in</asp:LinkButton>
Reference: multiple TargetControls for the ModalPopup
How to call the functional modal popup of master page from a control in child page??
Update:
This is in masterpage:
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="linkLog" CancelControlID="linkClose" BackgroundCssClass="cssModal" PopupControlID="panelPopUp" BehaviorID="programmaticModalPopupBehavior" PopupDragHandleControlID="panelDrag"></ajax:ModalPopupExtender>
Add an OnClientClick for the LinkButton, like this:
<asp:LinkButton ID="LinkButton1" runat="server" Text="Login 2" OnClientClick="return LogIn2()" ...>
Put the JavaScript function in your master page, and after showing the popup, have the method return false to prevent the LinkButton from doing a postback:
function LogIn2()
{
$find("<%=ModalPopupExtender1.UniqueID%>").show();
return false;
}
As an alternative, you may also add return false to the OnClientClick of the LinkButton, after the LogIn2 function has executed, like this:
<asp:LinkButton ID="LinkButton1" runat="server" Text="Login 2" OnClientClick="LogIn2();return false;" ...>
I m not sure about this but let me confirm are you using the control of ajax like given below
<asp:ModalPopupExtender ID="ImageUploaderEx" runat="server" BehaviorID="ImageUploaderBID" TargetControlID="Link Name" CancelControlID="Cancel" PopupControlID="Panel to be open" OnCancelScript="hideUploader()"></asp:ModalPopupExtender>
If Yes then you can use this same modal with a different name, If this doesnt work let me know I will try my best
try this if it works
((ModalPopupExtender)Page.Master.FindControl("ModalPopupExtender1")).Show();
and add this as well
using AjaxControlToolkit;

href link to trigger asp.net c# button event

I have a navigation bar consisting of list items. Right at the end of the nav bar I want a logout link:
//other links
...
<li>
logout
</li>
I have an event in my C# code called Logout_Click(object sender, EventArgs e) that I want to run when the user clicks the above navbar link, but obviously ordinary <a> tags don't trigger ASP.NET click events.
So I thought I'd be clever and create a HIDDEN <asp:Button> called logout that does trigger the Logout_Click function, and then get the JavaScript to click the button for me.. here is my code:
Log Out
<form runat="server">
<asp:Button ID="logout" runat="server" onclick="Logout_Click" Visible="false" />
</form>
But it still didn't work.
Can someone help me?
Try:
Log Out
Can you try without the Visible="false" on the asp:button?
And if it works hide it with css instead, style="display:none;"
I think the script needs the client side id of your asp.net control:
javascript:document.getElementById('<%=logout.ClientID').click()
Or you can use the __doPostBack function ...
http://wiki.asp.net/page.aspx/1082/dopostback-function/enter link description here
Why not you are using Asp.net LinkButton ?
It's easy to do this work with LinkButton.

Categories