To explain confusing title, here is the deal. I have user control which has Like button in it, and I load this User control dynamically multiple times on my homepage. When loading it dynamically I set src of like button iframe dynamically too, here is the method:
public void SetLikeButton(int ID)
{
facebookIframe.Attributes["src"] = "//www.facebook.com/plugins/like.php?href=" + HttpUtility.UrlEncode("http://www.sample.com/subpage/" + ID.ToString()) +
"&send=false&layout=box_count&width=50&show_faces=false&action=like&colorscheme=light&font&height=90";
}
But when I press any of Like buttons, only domain name is gets "liked" on user profile. I need it to share full path,rather than just domain name.Is that possible?
Can't help on the iframe version but this is based on the HTML5 version at
https://developers.facebook.com/docs/reference/plugins/like/
Div Tag for the markup
<div id="fbdiv" class="fb-like" data-href="" data-send="true" data-width="450" data-show-faces="true" runat="server"></div>
In pageload of control
fbdiv.Attributes["data-href"] = "http://www.yoursite.com";
If the control gets loaded multiple times add a parameter to change the URL
Related
I have cms flex menu control as web user control.
<CMS:FlexMenu ID="menu_box" CacheInterval="0" DisplayXslt="~XMLFiles/Menu.xslt" runat="server" />
In workarea i created ektron submenu. Now in code behind i need to getcurrentID to get current page. This is my first encounter with ektron controls so anyone knows how to get it ?
Thanks
If you just want to refer to the control on the page you would use
menu_box.[property];
menu_box.ID;
If you want to reference it in JavaScript you would use
ClientID + "_menu_box";
If you need to get that back to the page you can add a JavaScript function that does something like this:
JS.RegisterJSBlock(this, "alert('" + ClientID + "_menu_box');", "JavaScriptCodeBlock");
I have created a small web application for display the selected employees data. In this application I coded a javascript. I have create a dropdownbox with username details along with them a checkbox is in front of every user. These username get from database. I want that manager dropdown the list and select the employee which he want to see the details. I did this with the help of javascript but the issue is that it successfully display the usernames in dropdown when it is saparate form from the master page but when i merge it with master page means make it content page of that master page it doesn't display the usernames in dropdown.
It display it blank. Where I m doing wrong. Any suggestions will be appreciated.
Thanks in advance.
As Pleun says the masterpage will change the HTML control ids rendered to the browser. There are a couple of ways round this If you are using asp.net 4 you can specify the client ids as follows:
<asp:Label Text="text" runat="server" ID="SomeID" ClientIDMode="Static" />
That will maintain the ID rendered to the browser.
If you are user a previous version of asp.net then i tend to user JQuery to get the controls using something like:
$("[id$='SomeId']")
The $= means ends with.
You can also user server markup mixed in with your javascript code e.g.
var control = document.getElementById("<% =SomeId.ClientId %>");
asp.net will then render out whatever client side id it assigns to the control with server id SomeId
The master page changes the names of the controls:
Have a look here:
http://www.asp.net/master-pages/tutorials/control-id-naming-in-content-pages-cs
(Not your question - but the functionality can also be done out of the box with ASP.NET without coding javascript yourself)
You need to give the client id of the controls in the function.
When you were using master page den the id of ur controls changes.
For eg:
The clientID of Checkbox chktest will be chktest without master page.But with masterpage the clientID changes to something like 'ctl00_ContentPlaceHolder1_chktest'
So the javascript will not detect if you use chktest when using master page and your functions wont work as expected.So use clientId of controls.
Another issue I have in DNN5:
I'm currently creating a module that shows a GridView that has a "Edit" column.
When user clicks on "Edit" column, it should open an edit form in a new window.
This edit form is an ASPX-page inside my module folder and it expects a ModuleId parameter in order to access the module Settings; that part works fine and I'm able to retrieve the Module settings.
However, I still have the following issues:
How can I localize my Labels? I have tried DNN's label control, but no success. I also tried asp:Label with "meta:resourceKey", but it looks like it isn't able to access the local resource file.
It's very annoying to use Aspx-pages in my module since it will operate outside DotNetNuke's context. Does anybody knows an approach that allows me to use PortalModuleBase?
I have tought about displaying a DotNetNuke page in the new window, just by referencing the Control to load. However when I do that, it will show me the full page (so with navigation bar, footer, and so on) and I actually just want to show the control.
Besides, I'm only able to open my Aspx-page by referencing to /DesktopModules/MyModule/Page.aspx instead of DNN's NavigateUrl or so.
Thanks for your replies.
DNN will hide all other modules on the page whenever a control (or ctl=mycontrol) is specified for the page. So,
You should change your code from an ASPX page to an ASCX control.
Add the ascx control to the Module Controls section of your module's Module Definition.
Use DNN's NavigateURL function to generate the link. You'll want to use one of the options where you specify the Control Key (i.e. NavigateURL("edit", "SkinSrc=[G]" + Globals.QueryStringEncode( DotNetNuke.UI.Skins.SkinInfo.RootSkin + "/" + Globals.glbHostSkinFolder + "/" + "No Skin" ))
In the above sample, "edit" is the control key you specified for the control.
Why not load the edit interface in another ASCX file rather than an ASPX page? Check out http://dnnsimplearticle.codeplex.com for some examples in C#. It's a basic article module, but does a lot of useful things from a DNN perspective.
Mate for localization Aspx-pages operating outside DotNetNuke's context i suggest you to do it programatically. It will give you more control and you can debug it if some problem arises.
Like EfficionDave suggest use Control Key (i.e. NavigateURL("edit", "SkinSrc=[G]" + Globals.QueryStringEncode( DotNetNuke.UI.Skins.SkinInfo.RootSkin + "/" + Globals.glbHostSkinFolder + "/" + "No Skin" )) method
/Adnan Zameer
http://www.adnanzameer.com
I have an ASP.NET page with one control (.ascx) on it. The page (.aspx) onload assigns some text to a couple labels and passes a product ID to the .ascx control. The .ascx control, onload, takes that product ID from the .aspx page and hits the database several times, does several calculations, etc - basically takes a long time to load.
So when I'm clicking a link to this .aspx page, it is taking 7-10 seconds for the page to load. I've narrowed it down to the calculations on the .ascx control being the culprit and I've optimized the code as much as I can ... but it's still taking too long.
Is there a way to load the .aspx page BEFORE the control loads? (Maybe display a "Loading..." animation? Like used in an UpdateProgress?)
You could do this with an UpdatePanel. It will take a little trickery, but try something like this:
1) Put the UserControl in an UpdatePanel.
2) Put a public property on your usercontrol like IsEnabled that it will use to conditionally do nothing or render a "please wait." Set it false from your main page.
3) Add some code in OnInit to your main page:
if (MyScriptManager.IsInAsyncPostback) {
MyUserControl.IsEnabled=true;
}
4) Add a client script along these lines:
finished=false;
Sys.WebForms.PageRequestManager.pageLoaded(function(sender,args) {
if (!finished) {
finished=true;
__doPostBack('','');
// you can include the uniqueID of your updatepanel as the first arg
// otherwise it will refresh all update panels
}
});
or with jquery..
finished=false;
$(document).ready(function() {
if (!finished) {...
}
});
What this should do is cause an async postback to be initiated immediately after the page is done loading, which will in turn cause the update panel to be refreshed. Since you set it to be enabled when it's in an async postback, it will render itself the 2nd time.
The only possible way to achieve this is by setting it up as a separate HTTP resource. At the moment .NET is integrating the control into the page so that it is waiting unti it has everything it needs to respond.
You could do this a multitude of different ways:
Web Service that gets called via javascript
Seperate page which contains the control (and is hosted within an iFrame to appear to be on the same page)
The best way to do this would be to use an iFrame (or something similar) which will instruct the browser to request the control after the main page has been sent).
Personally, I would never use an iFrame to load content on a page - that's more like a hack than anything and plus, iframe == "bad".
But they are right, you won't be able to do anything like what you're looking for.
If the user control DOES NOT have any web controls that cause a postback (or have any form controls that you need to access during a postback), then I would use AJAX to request the data on the server after the page has already loaded and use javascript to display the content on the page.
The Scenario: I have an asp.net website where I show a div popup on page load for taking a few user details. When a user inputs the details, or closes the popup, I set up a flag cookie so that the popup is not displayed again for the user. The div is in the MasterPage so that it is displayed no matter on which page a user lands first time. The div contains an UpdatePanel which has all the controls required for taking the details. This whole functionality is working fine.
The Problem: Now this div popup is not showing(by setting display:none) on subsequent postbacks(which I want), but the html markup is still loading with the page unnecessarily adding to the page size. What I would idealy want to do is: Check if flag cookie is set. If no, show the popup, else remove the popup's markup from the page.
Now since the div is not a server control, I cannot possibly remove it and the all the controls inside it. So, I thought of removing the UpdatePanel from the page:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["flag"] != null)
{
if (Page.Controls.Contains(updpnl_contact))
{
Page.Controls.Remove(updpnl_contact);
updpnl_contact.Dispose();
}
}
}
But I guess this tends to work with dynamically added controls only, and since the control is added at Design Time, it is not being removed.
Is there any way I can achieve this?
If you add a runat="server" attribute to your <div> element, it will be available in the code-behind. You'll need an id on it as well. Then you can just toggle the Visible property. If this property is false, the control won't be rendered to the client (i.e. no HTML markup).
What you're trying to do is not at all the usual workflow. I tend to think that it will not work as it would mess up control tree, maybe even corrupt the viewstate and so on.
As a possible solution, you can put it's visibility to hidden in the code behind. This, in the contrary to the usual 'gut feeling', doesn't work like the css propery 'display:none' for example - instead the control will not even be rendered into the page when it's not visible. This may be the workaround for you.
Happy coding.
A more efficient approach would be to create the panel as a UserControl and load it dynamically in codebehind when it's needed, then add it to your page. E.g, in code:
MyPopupControl popup = (MyPopupControl)Page.LoadControl("/path/to/usercontrol.ascx");
PopupPanel.Controls.Add(popup);
Where PopupPanel is an empty <asp:Panel>. Then, not even the markup will need to be loaded/processed except when its needed.
There is no reason that all the code you use to display and process this panel couldn't also be in the usercontrol, isolating it from the master page.
Can you build the panel dynamically, based on the cookie setting?