PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

How could I change the NavigateUrl property at runtime based on another controls property ?

 
 
Radu
Guest
Posts: n/a
 
      24th Jan 2007
Hi, I have a "select" control named "cboSelectScorecardType", defined
as

<select id="cboSelectScorecardType"
size="1"
runat="server">
</select>

which shows a list of files on my drive. It does not post back, nor do
I want it to. After the user selects a document in the combo, I want a
hyperlink defined in the same page as

<asp:HyperLink
Target="_blank"
NavigateUrl="javascript:Concat();"
ID="cmdOpenScorecardPreview"
Text="here"
runat="server">
</asp:HyperLink>

to have the NavigateURL property set to whatever the combo points to,
so that the user can click on it to preview the document selected in
the combo, so therefore I tried to use this:

function MyConcat()
{
return String.Concat(
"~",
"\Scorecard Previews\",

cboSelectScorecardType.Items(cboSelectScorecardType.SelectedIndex).ToString,

".doc"
);
}

I confess I don't really know JavaScript.

What am I doing wrong ? Is there a simpler way to do this ? There is no
server event I can write my code into...

Thanks, Alex

 
Reply With Quote
 
 
 
 
Radu
Guest
Posts: n/a
 
      24th Jan 2007
Hi, Milosz, it works great, thank you very much !

:-)) raduspage.aspx... Cute :-))

I read the code, I translated it (mentally) from C# to VB (I don't know
much C#), and it makes sense.

However, I have one question: It says "OnChange is not a valid
attribute of element DropDownList" - however, hmmmmm, it works.

Thanks again - I'll work now on translating it into VB and
incorporating it into my program.

Alex (or.... Radu) :-))


On Jan 24, 10:47 am, Milosz Skalecki [MCAD] <mily...@REMOVEITwp.pl>
wrote:
> Hi radu,
>
> I see you don't quite understand the asp.net concept as you're mixing server
> and client sides. But don't worry, i created a simple example to help you
> with dynamic document previewing. Example consists of two pages, one
> containing combo box for selecting word document, and second, which displays
> the document. Please note you have to populate combo box with file names
> users can preview (i.e. using system.IO.File.GetFiles() method)
>
> -- begin raduspage.aspx html code --
>
> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadusPage.aspx.cs"
> Inherits="RadusPage" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <aspropDownList runat="server" ID="fileList" onchange="previewFile(this)">
> <asp:ListItem Text="Please select a file"/>
> <asp:ListItem Text="file1.doc"/>
> <asp:ListItem Text="file2.doc"/>
> <asp:ListItem Text="file3.doc"/>
> </aspropDownList>
> </div>
>
> <div style="padding: 10px; border: solid 1px black; width: 500px;
> height: 350px">
> <iframe src="preview.aspx" runat="server" id="viewer"
> frameborder="0"></iframe>
> </div>
>
> <script language="javascript">
> //<!--
> function previewFile(cbo)
> {
> var index = cbo.selectedIndex;
> // first item is ' please select...'
> if (index > 0)
> {
> var ifr = document.getElementById('<%=viewer.ClientID %>');
> ifr.src = 'preview.aspx?file=' + escape(cbo.options[index].text);
> }
> }
> //-->
> </script>
>
> </form>
> </body>
> </html>
> -- end --
>
> Second apsx page: Remove all html code from this page - leave
>
> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="preview.aspx.cs"
> Inherits="preview" %>
>
> only
>
> -- begin preview.aspx c# code behind --
>
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
>
> public partial class preview : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> string value = Request.QueryString["file"];
>
> if (String.IsNullOrEmpty(value))
> {
> Response.Write("File has not been selected yet.");
> }
> else
> {
> AttachFile(value);
> }
> }
>
> private void AttachFile(string file)
> {
> // i put my example word files in application's root directory
> file = Server.MapPath("~/" + file);
>
> if (System.IO.File.Exists(file))
> {
> // determine the MIME content type i.e. using extension
> // for word documents MIME type equals : application/msword
> Response.ContentType = "application/msword";
> Response.WriteFile(file);
> }
> else
> {
> Response.Write("File cannot be found");
> }
>
> Response.End();
> }
>
> }-- end c# code
>
> Hope this helps
> Milosz
>
>
>
> "Radu" wrote:
> > Hi, I have a "select" control named "cboSelectScorecardType", defined
> > as

>
> > <select id="cboSelectScorecardType"
> > size="1"
> > runat="server">
> > </select>

>
> > which shows a list of files on my drive. It does not post back, nor do
> > I want it to. After the user selects a document in the combo, I want a
> > hyperlink defined in the same page as

>
> > <asp:HyperLink
> > Target="_blank"
> > NavigateUrl="javascript:Concat();"
> > ID="cmdOpenScorecardPreview"
> > Text="here"
> > runat="server">
> > </asp:HyperLink>

>
> > to have the NavigateURL property set to whatever the combo points to,
> > so that the user can click on it to preview the document selected in
> > the combo, so therefore I tried to use this:

>
> > function MyConcat()
> > {
> > return String.Concat(
> > "~",
> > "\Scorecard Previews\",

>
> > cboSelectScorecardType.Items(cboSelectScorecardType.SelectedIndex).ToString*,

>
> > ".doc"
> > );
> > }

>
> > I confess I don't really know JavaScript.

>
> > What am I doing wrong ? Is there a simpler way to do this ? There is no
> > server event I can write my code into...

>
> > Thanks, Alex- Hide quoted text -- Show quoted text -


 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      25th Jan 2007
Hi again Radu,

Parser error "OnChange is not a valid attribute of element DropDownList" is
caused by the fact DropDownControl doesn’t have such property, but it will be
rendered as expected in representing HTML code (as you may know dropdownlist
renders as <select> html tag). Such trick is allowed and it’s called
“expando”. You can of course avoid it, removing OnChange=”” attribute from
DropDownList and add it programmatically onpageload event handler:

cboSelectScorecardType.Attributes["onchange"] = "previewFile(this)"

Regards

Milosz



"Radu" wrote:

> Hi, Milosz, it works great, thank you very much !
>
> :-)) raduspage.aspx... Cute :-))
>
> I read the code, I translated it (mentally) from C# to VB (I don't know
> much C#), and it makes sense.
>
> However, I have one question: It says "OnChange is not a valid
> attribute of element DropDownList" - however, hmmmmm, it works.
>
> Thanks again - I'll work now on translating it into VB and
> incorporating it into my program.
>
> Alex (or.... Radu) :-))
>
>
> On Jan 24, 10:47 am, Milosz Skalecki [MCAD] <mily...@REMOVEITwp.pl>
> wrote:
> > Hi radu,
> >
> > I see you don't quite understand the asp.net concept as you're mixing server
> > and client sides. But don't worry, i created a simple example to help you
> > with dynamic document previewing. Example consists of two pages, one
> > containing combo box for selecting word document, and second, which displays
> > the document. Please note you have to populate combo box with file names
> > users can preview (i.e. using system.IO.File.GetFiles() method)
> >
> > -- begin raduspage.aspx html code --
> >
> > <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadusPage.aspx.cs"
> > Inherits="RadusPage" %>
> >
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> >
> > <html xmlns="http://www.w3.org/1999/xhtml" >
> > <head runat="server">
> > <title>Untitled Page</title>
> > </head>
> > <body>
> > <form id="form1" runat="server">
> > <div>
> > <aspropDownList runat="server" ID="fileList" onchange="previewFile(this)">
> > <asp:ListItem Text="Please select a file"/>
> > <asp:ListItem Text="file1.doc"/>
> > <asp:ListItem Text="file2.doc"/>
> > <asp:ListItem Text="file3.doc"/>
> > </aspropDownList>
> > </div>
> >
> > <div style="padding: 10px; border: solid 1px black; width: 500px;
> > height: 350px">
> > <iframe src="preview.aspx" runat="server" id="viewer"
> > frameborder="0"></iframe>
> > </div>
> >
> > <script language="javascript">
> > //<!--
> > function previewFile(cbo)
> > {
> > var index = cbo.selectedIndex;
> > // first item is ' please select...'
> > if (index > 0)
> > {
> > var ifr = document.getElementById('<%=viewer.ClientID %>');
> > ifr.src = 'preview.aspx?file=' + escape(cbo.options[index].text);
> > }
> > }
> > //-->
> > </script>
> >
> > </form>
> > </body>
> > </html>
> > -- end --
> >
> > Second apsx page: Remove all html code from this page - leave
> >
> > <%@ Page Language="C#" AutoEventWireup="true" CodeFile="preview.aspx.cs"
> > Inherits="preview" %>
> >
> > only
> >
> > -- begin preview.aspx c# code behind --
> >
> > using System;
> > using System.Data;
> > using System.Configuration;
> > using System.Collections;
> > using System.Web;
> > using System.Web.Security;
> > using System.Web.UI;
> > using System.Web.UI.WebControls;
> > using System.Web.UI.WebControls.WebParts;
> > using System.Web.UI.HtmlControls;
> >
> > public partial class preview : System.Web.UI.Page
> > {
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > string value = Request.QueryString["file"];
> >
> > if (String.IsNullOrEmpty(value))
> > {
> > Response.Write("File has not been selected yet.");
> > }
> > else
> > {
> > AttachFile(value);
> > }
> > }
> >
> > private void AttachFile(string file)
> > {
> > // i put my example word files in application's root directory
> > file = Server.MapPath("~/" + file);
> >
> > if (System.IO.File.Exists(file))
> > {
> > // determine the MIME content type i.e. using extension
> > // for word documents MIME type equals : application/msword
> > Response.ContentType = "application/msword";
> > Response.WriteFile(file);
> > }
> > else
> > {
> > Response.Write("File cannot be found");
> > }
> >
> > Response.End();
> > }
> >
> > }-- end c# code
> >
> > Hope this helps
> > Milosz
> >
> >
> >
> > "Radu" wrote:
> > > Hi, I have a "select" control named "cboSelectScorecardType", defined
> > > as

> >
> > > <select id="cboSelectScorecardType"
> > > size="1"
> > > runat="server">
> > > </select>

> >
> > > which shows a list of files on my drive. It does not post back, nor do
> > > I want it to. After the user selects a document in the combo, I want a
> > > hyperlink defined in the same page as

> >
> > > <asp:HyperLink
> > > Target="_blank"
> > > NavigateUrl="javascript:Concat();"
> > > ID="cmdOpenScorecardPreview"
> > > Text="here"
> > > runat="server">
> > > </asp:HyperLink>

> >
> > > to have the NavigateURL property set to whatever the combo points to,
> > > so that the user can click on it to preview the document selected in
> > > the combo, so therefore I tried to use this:

> >
> > > function MyConcat()
> > > {
> > > return String.Concat(
> > > "~",
> > > "\Scorecard Previews\",

> >
> > > cboSelectScorecardType.Items(cboSelectScorecardType.SelectedIndex).ToString*,

> >
> > > ".doc"
> > > );
> > > }

> >
> > > I confess I don't really know JavaScript.

> >
> > > What am I doing wrong ? Is there a simpler way to do this ? There is no
> > > server event I can write my code into...

> >
> > > Thanks, Alex- Hide quoted text -- Show quoted text -

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime error 380 - Could not set the list property. Invalid property value. viktorka.mail@gmail.com Microsoft Excel Programming 3 27th Feb 2007 06:35 AM
Property Grid with Dynamic Property values at runtime Joe Microsoft C# .NET 0 29th Aug 2006 04:52 PM
Runtime Error 380 Could not set the list property. Invalid property value BernzG Microsoft Excel Programming 0 19th Aug 2005 05:22 AM
Runtime error 380: Could not set the List property. invalid property value of listbox jasgrand Microsoft Excel Programming 0 6th Oct 2004 09:28 PM
The controls on this property sheet are disabled because one or more other Network property sheets are already open. To use these controls, close all these property sheets and then reopen this one. =?Utf-8?B?Um9iZXJ0?= Microsoft Windows 2000 Networking 1 11th Apr 2004 12:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:51 AM.