Last post Nov 09, 2007 05:16 PM by email@example.com
Nov 08, 2007 01:00 PM|muybn|LINK
My predecessor wrote the following ASP 1.1 code, which causes errors when I try to look at the page in Design View. What are some alternatives to this?
<a style="cursor:hand" onclick="openDCN(<%# Convert.ToString(((DataRowView)Container.DataItem)["dcn"]) %>);"><%# Convert.ToString(((DataRowView)Container.DataItem)["dcn"]) %></a>
<asp:HyperLink Text="" NavigateUrl='<%# BuildInvoiceHistoryLink(Convert.ToString(DataBinder.Eval(Container.DataItem,"dcn"))) %>' runat="server" target="_new" >
<img src="images/icon_review_history.gif" border="0" height="17" width="20" />
Nov 08, 2007 02:21 PMfirstname.lastname@example.org|LINK
I am guessing this piece of code is inside a repeater or datagrid. If you really wanted to be able to view the code in design view you could make the anchor link a hyperlink server control and set the onclick via the attributes property and the text on the
repeater/datagrid/datalist on_ItemDataBound event, and do the same for the exisitng Hyperlink server control i..e set teh NavigateURL on the DataBound event. This would remove all of the ASP.net binding tags from the HTML source enabling you to view the page
in design view.
For a quicker solution try a better HTML editior like Microsoft Expression Web or Visual Studio 2008 they may have better support for displaying pages in design view with lots of code tags.
Nov 08, 2007 02:48 PM|muybn|LINK
Thanks for your quick response, Scott. You're right, the code mentioned is contained in a Datagrid. I'll try out your suggestions and mark your post as an answer if successful, or come back for more. Unfortunately, I've been unable to convince my department
to upgrade to a higher version than 1.1 so far. I work with 2.0 on my personal machine and find that it's able to process over stuff like this. They know that we eventually have to upgrade, but it's mainly the time commitment (in my experience, the 1.1 to
2.0 converter wizard is very error-prone). Each of us has 2.0 installed, but all for naught at present.
Nov 08, 2007 03:16 PMemail@example.com|LINK
To be honest with you I am not sure you would even be able to display the designer view in visual 2005. Download a trial of Expression web.. or is it Web Expression from microsoft or even Dreamweaver it make give you a better design time experince. What I used
to do is remove all the lines like the above (the ones that upset the designer) then switch to design view, arrange my page and then put the lines back in! :0)
Nov 08, 2007 05:54 PM|muybn|LINK
Can you please suggest what might be wrong, or what else I need to do, with the following code. It's not showing the link to the document.
Sub Page_Load(sender As Object, e As EventArgs)
<asp:HyperLink ID="lnkDCN" style="cursor:hand" Runat="server" />
<asp:HyperLink ID="lnkDCNHistory" Text="" NavigateUrl='<%# BuildInvoiceHistoryLink(Convert.ToString(DataBinder.Eval(Container.DataItem,"dcn"))) %>'
target="_new" ImageUrl="images/icon_review_history.gif" BorderWidth="0" height="17" width="20" runat="server"/>
Nov 08, 2007 06:16 PMfirstname.lastname@example.org|LINK
That won't work, the code needs to be on the datagrid on databound event. On the databound event find the HyperLink called lnkDCN and then set the attributes. Something like:
Private Sub DataGrid1_ItemDataBound(s As Object, e As DatagridItemEventArgs)
Dim drv as DataRowView = Ctype(e.DataItem, DataRowView)
Ctype(e.item.FindControl("lnkDCN"), HyperLink).Attributes.Add("onClick", drv("dcn"))
Do you follow?
Nov 09, 2007 04:52 PM|muybn|LINK
I finally figured out the solution after much agony and trial & error. I had a nagging feeling that there must be a way to do this without the OnClick in code-behind that you describe since the NavigateUrl in ASP hyperlink itself already handles OnClick.
I guess I led you on a wild goose chase since I had raised the subject of OnClick from the previous code, so I'm sorry about possibly wasting your time...but you did get me thinking. Thanks again. This is the solution I came up with:
string openDCN(String dcn)
return "document-ds.aspx?dcn=" + dcn;
<asp:HyperLink ID="lnkDCN" style="cursor:hand" text='<%#
(The other person had written "openDCN" as a function and I couldn't get it to work with this hyperlink, so I tried it as written above and it worked. Don't ask me why.)
Nov 09, 2007 05:16 PMemail@example.com|LINK