472,778 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,778 software developers and data experts.

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

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(cboSelectScorecardTyp e.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

Jan 24 '07 #1
2 10761
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>
<asp:DropDownList 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"/>
</asp:DropDownList>
</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(cboSelectScorecardTyp e.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 -
Jan 24 '07 #2
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 <selecthtml 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>
<asp:DropDownList 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"/>
</asp:DropDownList>
</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(cboSelectScorecardTyp e.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 -

Jan 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chuck Ritzke | last post by:
Hi, I've searched the newsgroup and other sources to understand how to handle runtime controls and see I'm not the only one who's confused, but I'm still not quite sure of the best way to handle...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
by: Joel D Kraft | last post by:
I'm using controls in my ASP.NET application from a couple of vendors. Between the vendors and thier versioning, I've set up subfolders under my bin directory: bin bin\Infragistics\v5.2...
3
by: euan | last post by:
Hey guys, I am just playing around with asp.net 2.0 and I was reading about the image control (for mobile designer) and thought that would be handy. So I have created: Do While...
1
by: jeanluc.praz | last post by:
I created a user control containing containing a few hyperlinks. How can I change the NavigateUrl inside the user control ? So far I did the following: 1) In the custom control Public...
5
by: Vear | last post by:
Sorry, very Newbie question here. I don't know what I'm doing wrong. I have to use a <asp:hyperlink> to go to another page. I want to pick up the value in a text box. This is what I've tried and It...
6
by: eswanson | last post by:
In jscript, I would like to be able to set the href attribute of the anchor element. I have a aspnet:hyperlink button on the page, but I would like to be able to set the href attribute of this...
5
by: Joe | last post by:
Is there anyway to change the name or add a property to and existing class in .NET 1.1? For example if I have a property called Name and I want to change it to MyName. -Joe
5
by: TS | last post by:
I have a custom textbox that i need to access a label's text property. the label and textbox are 2 separate controls that will be on my page. Inside my custom control i want to have access to this...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.