i am making a user control dynamically.
var controlMarkup = string.Empty;
Page page = new Page();
var customControl = page.LoadControl(control) as UserControl;
if (customControl != null)
{
var htmlForm = new HtmlForm();
var output = new StringWriter();
//output.Write("<div id = 'ControlName'>" + customControl + "</div>");
htmlForm.Controls.Add(customControl);
page.Controls.Add(htmlForm);
HttpContext.Current.Server.Execute(page, output, false);
controlMarkup = output.ToString();
}
return controlMarkup;
nut now i want to get the textbox id of user control in external javascript can anyone help me to get the id of control.
Try this $get("<%=lblDistance.ClientID%>")
The client-side ID can be found in the ClientID property. For example, you can hide a control called txtDistance using jQuery in the .aspx page like:
$('#<%= lblDistance.ClientID %>').hide();
If you are using .net 4.0 add ClientIDMode="Static" to your control.
Something like:
yourControlname.Attributes.Add("ClientIDMode", "Static");
For previous version of .net, because you are using external javascript you have two options
Use hidden input to store clientId's
View HTML produced by your page and use those Id's in your external javascripts
I have got the solution of this Problem i just use the javascriptserializer to get the client id's of the dynamic control its very good approach because RegisterCLientScript is a methos which write the string from JavaScript Serializer on the page then u can easily get ur desired ID,s of the dynamic Control
Related
Hi I am completely new to Sharepoint and wiki pages. I manage to do few changes to wiki pages to have a feel of it. I noticed that every time i create a link to a document if the version changes i need to update the link manually by editing it. Is there any way to automate this process?
Eg: Docv1.0.doc is updated to Docv2.0
Thanks
When you change a document, you don't need to change the file name. SharePoint has versioning built in, so you can keep the file name the same.
That's the only solution actually, don't change the filename. Enable versioning on the library to be able to see previous versions.
Sharepoint site has several links to templates and documents that points to a shared server and these documents can be updated as new versions, so the links to this files needs to be updated automatically, in fact these links need to call some script for dynamically linking them to the latest files. (not sure if a better way of doing this without a script). Here is what I could manage to do, a better and other options to achieve will be appreciated.
I manage to get something working using webparts Content Editor and linking it to a file. Not sure if this the only/best approached for Sharepoint 2007
<script type="text/javascript">
function getLatestFile(){
var myObject;
var recent = "";
myObject = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = myObject.GetFolder("C:\Test");
var fc = new Enumerator(folderObj.files);
for(var objEnum = new Enumerator(FileCollection); !objEnum.atEnd(); objEnum.moveNext()) {
If (recentFile = ""){
recentFile = file;
else if (file.DateLastModified > recentFile.DateLastModified){
recentFile = file;
}
}
}//for loop
alert("recentFile : " + recentFile);
var mylink = document.getElementById("myLink");
mylink.setAttribute("href", urlToFile);
mylink.click();
}
</script>
<P> </P><A id="myLink" onclick="getUrl();"> TestFile1 </A>
Content Type Editor
check above link for more on using content links to use JavaScript and HTML.
I have a Javascript function, where I want to call jQuery.Load() to load a file. How would I get ASP.Net to fill in the local server name, so that I can just give a relative path?
The reason for that is I can give the base, say "http://www.mydomain.com/", however I would like to be able to test locally and not have to publish on every single build. I just want to load a local file.
My first thought was just "/MyFolder/MyPage.aspx", but that did not work. I then thought of "~/MyFolder/MyPage.aspx", but that did not work either.
I figure it should be some sort of ASP.Net directive to prepend, just I am not sure what.
I wanted to give some code to show the actual use and what worked.
<head runat="server">
<script type="text/javascript">
// <![CDATA[
function DoPopupSignin()
{
var urlLoad = "http://" + window.location.host + '/Candiates/Login.aspx';
// Triggering bPopup when click event is fired
$('#popupSigninMaster').bPopup({
//modalClose: false,
//opacity: 0.6,
//positionStyle: 'fixed', //'fixed' or 'absolute'
content: 'iframe', //'iframe' or 'ajax'
contentContainer: '.content',
loadUrl: urlLoad, //Uses jQuery.load()
});
}
// ]]>
</script>
</head>
I am trying to get my jQuery Popup working loading the contents from another file. My code uses the free jQuery popup control that I found jQuery.bPopup.js.
In JavaScript as you are preparing your query, you can use window.location.host.
var path = window.location.host + '/relative/path/file.ext';
$.load(path);
It's a recurring pain, but I use something like this:
public static Uri ToAbsoluteUri(this string path)
{
Uri uri;
if (Uri.TryCreate(path, UriKind.Absolute, out uri)) return uri;
var serverUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
var serverUri = new Uri(serverUrl);
return new Uri(serverUri, path);
}
Controls / Forms in .NET have a ResolveUrl(string) method that will allow you to resolve relative paths using ~/ pathing. Otherwise you use the VirtualPathUtility static class.
I'm trying to dynamically set the thumbnail shown when sharing to Facebook using javascript. I tried adding the meta tag "og:image" to the page (it's a JSP) and that works, but what I want to do now is to replace such image with another one dynamically loaded by javascript.
Basically, the page is calling an API upon loading, using javascript, and retrieves a list of images. I want to use one of those as the thumbnail.
I tried using javascript to replace the content of the meta tag, but Facebook doesn't seem to care abou t it (it does change if I check with my browser).
Is it possible to do this?
Thanks in advance!
Here is a function I used to extract the image url from a flash object tag's flashvars parameter, and then assign it to a meta tag by using jquery:
$(window).load(function(){
//Use $(window).load() instead of $(document).ready(), so that the flash code has loaded and you have all the html you need process with javascript already in place when you start processing.
var stringToExtractFrom = $('param[name="flashvars"]').attr('value');
//Get the flashvars parameter value which we'll use to extract the preview image url from.
var pos = stringToExtractFrom.indexOf("&");
//Search for the position ampersand symbols which surround the image url.
var stringToUse;
//The final string we'll use.
var startOfImageSrc = null;
//The first position where we discover the ampersand
var endOfImageSrc;
//The second position where we discover the ampersand
var lengthToSubstract
//How many symbols to chop off the flashvars value.
while(pos > -1) {
if(startOfImageSrc == null){
startOfImageSrc = pos;
}
else {
endOfImageSrc = pos;
lengthToSubstract = endOfImageSrc - startOfImageSrc;
}
pos = stringToExtractFrom.indexOf("&", pos+1);
}
stringToUse = stringToExtractFrom.substr(startOfImageSrc+7, lengthToSubstract-7);
$('meta[property="og:image"]').attr('content', stringToUse); });
Facebook robot never runs a java script code
but why you don't try to set og tags in in server-side ?
Can I get print data in my .js files before sending them to the client? I want to be able to print the session id into a variable to use in getting around the flash cookie bug. Here's my code:
//Add our custom post-params
var auth = "<% = If(Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing, String.Empty, Request.Cookies(FormsAuthentication.FormsCookieName).Value) %>";
var ASPSESSID = "<%= Session.SessionID %>";
this.setPostParams({
ASPSESSID: ASPSESSID,
AUTHID: auth
});
That shows up exactly the same way in my js file. I want the server to process the code!
You can not include the .NET markup in the js file. You can use an ashx file to generate a dynamic script files if you really want to do it.
Why write it in the JS file? Write it to the page with ClientScriptManager.RegisterClientScriptBlock so the JavaScript can be cached properly. The script will still be able to access the variable in the page as long as the included script appears after the code.
I think you want to use immediate if. Like:
var auth = "<% = iif(Request...
I am creating a webapp and I have been using tag in my JSPs to ensure that all my links (both to pages and to resources such as images/css) are always consistent from the root of the application, and not relative to my current location.
Some of the content I am creating using jQuery, for example, I am creating a HTML table by parsing a JSON object and using jquery.append() to insert it in to a div.
My question is, if I want to dynamically create a link using jquery how can I achieve a consistent URL regardless of the page being executed? I have tried just building the html with the tag in it, but no joy.
Thanks!
var baseURL = "/* Server-side JSP code that sets the base URL */";
$("<a />", { href: baseURL+"/my/resource/here.jsp" }); //Your proper link
Or you could do:
var baseURL = "http://"+location.host+"/my/base/url/";
//Which gives you something like http://mySite.com/my/base/url/
Get the root value of your webapp into a string using a jsp tag inside your javascript.
var root = < %=myRootVariable%> //This evaluates to http://www.myapp.com
var dynamicBit = "/foo/bar"
var dynamicLinkUrl = root + dynamicBit
var $newa = $("Hello, world");
$someJQElement.append($newa)
Hopefully none of this will occur in the global namespace. Just sayin'