Object Tags and Asp - asp.net

I have a master page that gets all its images from a table on a database, and I am trying to incorporate flash, for banners, but I can't quite seem to figure it out.
Right now there is a:
<asp:image id="headerimg" runat="server">
and that generates the appropriate img tag needed to show an image in html. Now I would like to know if there is any way where I can generate an object tag if a .swf file is present and populate the tag with width height and data and also not show the img tag.
Update__
I now have made a usercontrol that will create the object tag, but can someone please tell me if it is looking like I am doing it right..
IDataReader dr = DB.GetRS("SELECT HeaderGraphic,HeaderAlign, fWidth, fHeight, Flash FROM Store where CustomerID='" + Session["Customer"].ToString() + "'");
if(dr["Flash"] == 1)
{
HtmlGenericControl obj = new HtmlGenericControl("object");
obj.Attributes["width"] = dr["fWidth"];
obj.Attributes["height"] = dr["fHeight"];
obj.Attributes["data"] = dr["HeaderGraphic"];
this.Controls.Add(obj);
}
else
{
HtmlGenericControl image = new HtmlGenericControl("img");
img.Attributes["src"] = dr["HeaderGraphic"];
img.Attributes["align"] = dr["HeaderAlign"];
this.Controls.Add(image);
}
is this continuing to look right? and is there anything I am missing?
Thanks.

Why not create a user control that generates the required <OBJECT /> html to display the swf file and then you can dynamically load these if there are swf file present?

is this looking right? and how do I get this into the html?
Yes it looks right. You can add it into your page this way:
this.Controls.Add(obj);
Hope it helps!
Hanlet
EDIT: I could recommend you to look into Generic Handlers and see if you can somehow use it. Good luck!

Related

Create Temporary Page

can someone point me to the right direction
I need a code to dynamically create a temporary Web Pop-up Page which I'll declare the HTML Content in ASP.NET Using VB
reason for this function is that I am trying to make Application Form printer and I need to print the current page with the
<script>window.print();</script>
You could generate the entire HTML as string and then use as below:
window.open("data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>");
Basically,
window.open("data:text/html;charset=utf-8," + YOUR_HTML + "<script>window.print();</script>");
Copy paste the below script in a browser to test:
data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>
== Updates ==
Aspx.vb Code
Dim htmlText As String = "<head></head><bod‌​y><h3>Test Document</h3></body>".Normalize()
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "tempWindow", "<script>openTempWindow('" + htmlText + "')</script>", False)
Aspx Code
<script type="text/javascript">
function openTempWindow(content) {
var win = window.open("");
win.document.write(content);
}
</script>
You can achieve that by manipulating the response. This is one way to dinamically create an HTML document. For example:
HttpContext.Current.Response.Write("<html>
<body>
<h1>Something to print</h1>
</body>
<script>window.print();</script>
</html>")
In order to make it a popup window, in your base page you can implement window.open() function after, lets say, a button click. For example:
window.open("../pageReturningDynamicHTML.aspx?someParam=someValue")
In the provided link you can find more examples on how to open a window as popup with settings as sizes and more.

embedding images in asp.net Custom Control

I am creating a custom Gridview control, according to requirement i have to place two image buttons in the Top Pager. where i am able to display imagebuttons in top pager but only one image imagebutton shows the image another imagebutton does not.
Here is code:
protected override void InitializePager(GridViewRow row,int columnSpan,PagedDataSource pagedDataSource)
{
//adding refresh button in TopPager
ImageButton Refresh = new ImageButton();
Refresh.ToolTip = "Refresh GridView";
Refresh.ImageAlign = ImageAlign.Right;
Refresh.AlternateText = "Refresh GridView";
ClientScriptManager cs1 = this.Page.ClientScript;
Refresh.ImageUrl = cs1.GetWebResourceUrl(typeof(myCustomGrid.CustomGrid), "myCustomGrid.Refresh.gif");
// adding button in TopPager to add new record..
ImageButton ExportToPDF = new ImageButton();
ExportToPDF.ToolTip = "Export To PDF";
ExportToPDF.AlternateText = "PDF Export";
ClientScriptManager cs2 = this.Page.ClientScript;
ExportToPDF.ImageUrl = cs2.GetWebResourceUrl(typeof(myCustomGrid.CustomGrid), "myCustomGrid.PDF.gif");
}
I have set both images properties build action to embedded resource
in assembly.info
[assembly: WebResource("myCustomGrid.Refresh.gif", "image/gif")]
[assembly: WebResource("myCustomGird.PDF.gif", "image/gif")]
where i am going wrong! any help is much appreciated.
Does this images placed in root of the project? Because, if not you have to add relative path. And I don't see path from asssembly.
You have to make like this:
[assembly: WebResource("{Your assembly full name}.{Path to image inside assembly and with replacement '/' to '.'}.{Image name}", "image/gif")]
For example:
[assembly: WebResource("MyBestProject.Controls.resources.images.myCustomGird.PDF.gif", "image/gif")]
Could be a typo.
Did you mean :-
[assembly: WebResource("myCustomGrid.PDF.gif", "image/gif")]
and not...
[assembly: WebResource("myCustomGird.PDF.gif", "image/gif")]
Update:
when the imagebuttons renders the HTML generated by Refresh.gif and PDF.gif imagebuttons respectively.The PDF.gif does not load instead i get the alternate text specified which is in this code line ExportToPDF.AlternateText = "PDF Export";
<input align="right" type="image" style="height:20px;width:20px;" alt="Refresh GridView" src="/WebResource.axd?d=CIOcfTt92OMP_aqepr-cGa2E4E8-uaiywsae5-4NcYocrJ-NE-cIL4Qb2JfX3tY0cIa8EwDzWnyeBqNiST34SNpBNuGjVC113XqMTprBN-XU9J7ilPsI6bsaXwHa-Qt30&t=634589418951556073" title="Refresh GridView" name="ctl00$MainContent$customGrid0$ctl01$ctl02">
<input type="image" style="height:20px;width:20px;margin-left:480px;" alt="PDF Export" src="/WebResource.axd?d=su3rsVMzKa7BNi4A-JZVUHPhHh3sS-oWW9bmAeK4I0h1A11NHqBD2setFyA3yundDC34YO0gbBoz5G0PHS0uxeQYI66QON_syQhIdlIKs4JzJW6H_oLErMjOZE6Q_slB0&t=634589418951556073" title="Export To PDF" name="ctl00$MainContent$customGrid0$ctl01$ctl01">
"only" 2 years later, I had a similar issue. I just resolved mine with a simple idea that came by looking at the similarities between this post and my issue. Perhaps someone else will find this solution useful in the future.
The problem appears to be with the ALLCAPS section of the name. For some reason, UpperLower names work fine, as do all lower. But I am guessing ALLCAPS segments get converted to something else internally and don't work. In my case, renaming my icon from "ARROWLEFT.GIF" to "ArrowLeft.gif" (file name, registration, and any references to the resource) fixed the issue.
Additional Note: I had another image in the same project, named "icon_Calendar.GIF" which also wasn't working until I renamed it to "icon_Calendar.gif".

using JavaScript, find the ClientID of .NET control nested deep within a master page

The short question:
*takes deep breath*
How I can ClientID of TableRow inside Table added to PlaceHolder, which is in a UserControl inside a Web Part added to a SharePoint page using a MasterPage?
The explanation:
I'm building a usercontrol that dynamically shows SPList items, one per Web.UI.Table(). The 2nd row of the Table() will be hidden at first, with an image used to initiate some JavaScript to hide/show the row at the clients browser (rather than use postback or ajax - I have reasons).
The Table() is then added to a PlaceHolder in a UserControl, which is then used by a WebPart, and that WebPart is added to a SharePoint Page, which of course uses a MasterPage. I'm having real trouble working out the JavaScript method to find the ClientID of the TableRow, given that it's nested so deeply.
My .ascx code looks something like this..
<script type="text/javascript">
function showHidden(itemId) {
var controlId = document.getElementById('<%= phDownloadTable.ClientID %>');
//alert(controlId);
document.getElementById(controlId).style.display = (document.getElementById(controlId).style.display == "table-row") ? "none" : "table-row";
}
</script>
<asp:PlaceHolder ID="phTable" runat="server"></asp:PlaceHolder>
and my .cs codebehind is something like this..
Table myTable = new Table();
TableRow hiddenRow = new TableRow();
hiddenRow.ID = "row" + itemId;
hiddenRow.Attributes.Add("style","display: none;");
... create TableCells and add to hiddenRow...
TableRow displayRow = new TableRow();
TableCell toggleCell = new TableCell();
Image toggleImage = new Image();
toggleImage.ImageUrl = "/images/myimage";
toggleImage.Attributes.Add("onclick","javascript:showHidden('" + hiddenRow.ClientID + "');
toggleCell.Controls.Add(toggleImage);
displayRow.Cells.Add(toggleCell);
... create more TableCells and add to displayRow
myTable.Rows.Add(displayRow);
myTable.Rows.Add(hiddenRow);
the result is that the toggleImage "onclick" attribute shows showHidden('row999');, which passes 'row999' to the JavaScript function, but I cannot figure out there how to get the full clientId of the TableRow it refers to.
The source of my page shows the clientId to be ctl00_SPWebPartManager1_g_eda9b9e9_4c7a_48e0_a2aa_fd8cdd65de6c_ctl00_row999, which is longer than I'm used to seeing, and seems to contain two 'ct100_' parts, suggesting multiple levels of controls.
Any ideas would be greatly appreciated. I've tried all the usual avenues (googleing for 'javascript .net control client id' and the like, but so far I've not found anything that helps. Most suggest document.getElementById('<%= myControl.ClientId %>')... which is fine, but I don't know 'myControl' - I need that send from the toggle image.
Fingers crossed!!
Kevin
If you cant set the client id, you should be able to set a class, and that should be respected by .nat.
Them you can select the element by class name.
JavaScript has no wildcard selection options. Try using jQuery, that makes things more flexible.
Then you can use something like:
$("tr[id*='<%= phDownloadTable.ClientID %>']").css("display", your value);
this way you will still find the right element, even when it's moved to another place on the page.
Here is a more detailed explanation on how to use these wildcard selectors:
http://api.jquery.com/attribute-contains-selector/
With plain JavaScript you can do a document.getElementsByTagName('tr') and then loop those to find the right object.
If you are using Framework 4.0 you can set the ClientIdMode of the page like this:
Page.ClientIDMode = System.Web.UI.ClientIDMode.Static;
That way you can have more predictable client ids. For example, you can have id's without all the ctl00_ prefixes.

Setting multiple literals that contain the same text in ASP.NET

I have instances where I need to dynamically load 5-10 literals with the same text value. It seems like there has to be a more elegant way of doing it than setting the TEXT property of all the controls to the same value. Any methods out there that I'm not aware of? I thought about setting a protected property on my webform, and then using inline code on my aspx page. Is that a good approach?
Edit: I should add that I also want to handle the situation where a designer could simply add another place to load dynamically to the aspx file on the web server without having to do another rollout.
Pseudo code:
var literals = new List<Literal>() { l1,l2,l3 ...} ;
literals.ForEach(x=>x.Text = "some value");
When faced with the same problem I often use:
litOne.Text = litTwo.Text = litThree.Text = "some value";
It's not perfect but at least it's on one line.
How about this?
foreach (ITextControl textControl in new[] { literal1, literal2, literal3 })
{
textControl.Text = "foo";
}
You could even be fancier and just loop through all controls and check only those that implement the ITextControl interface or so.

Flex 3: Is it possible to use a remote image as the icon for a LinkButton?

We are creating a LinkButton programmatically and would like to set it's icon to an image retrieved from the remote server rather than something embedded within the SWF. The .icon property expects a Class but I can't figure out how to create one equivalent to an #Embed but from a dynamically generated URLRequest or URL String.
var myImage:Image = new Image();
myImage.source = "http://www.domain.com/img/1234.png";
myImage.width = 16;
myImage.height = 16;
myImage.scaleContent = true;
var myButton:LinkButton = new LinkButton();
myButton.label = "Some text"
// This is what I'm trying to figure out.
myButton.setStyle("icon", ???)
I'm probably missing something obvious - I've tried passing in the URL and myImage separately but both throw errors. Stepping into the setStyle() method shows that the code is expecting a Class - so what do I pass in place of the ???
I can't embed the image itself because it's dynamic - the URL is different each time the software runs.
Thanks for any assistance!
Why not just set the buttonMode of a mx:Image to true then add a click event?
<mx:Image source="{imageSource}" buttonMode="true" click="action()" />
I'm not sure its possible without using an embedded images with a linkButton
This might be worth a read
Edit... in AS3:
var img:Image = new Image();
img.source = "...";
img.buttonMode = true;
img.addEventListenever(MouseEvent.CLICK, funcName);
I think that instead of trying to set the style, you need to change the child object that holds the icon. You can access it by something like:
Var:Bitmap icon = myButton.getChildByName("upIcon") as Bitmap
It should be easy to replace the bitmapData in there with the one from a Loader.
If memory serves, you'll want to use button.setStyle('icon', img), where img is an image loaded via Loader class.
for laalto,
this may be too late of an answer but somebody might find it useful or as a starting point to a solution to your problem. Have you tried referencing your image icon as a class? I don't know if this will work for an image which is in a dynamic URL but this worked for me:
[Embed("assets/LinkButton.png")]
private const linkButtonIcon:Class;
Then in your code:
myButton.setStyle("icon", linkButtonIcon);
See this example here:
http://blog.flexexamples.com/2008/09/03/setting-the-icon-on-a-linkbutton-control-in-flex/
<mx:Button id="example" label="Example" icon="{IconUtility.getClass(example, 'http://www.exampledomain.com/image.jpg')}" />
http://blog.benstucki.net/?p=42

Resources