 |
| HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 4th, 2003, 01:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What code do you register in your RegisterClientScriptBlock method?
Can you post the relevant parts of your HTML page, including the JavaScript?
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 4th, 2003, 01:47 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The RegisterClientScriptBlock code is:-
Page.RegisterClientScriptBlock("FileSelected", "<script Language=javascript>function FileSelected(){" + Page.GetPostBackEventReference(this.inpImageFile) + "}</script>");
...and the relevant parts of the HTML page are:-
<script language="javascript">
function inpImageFile_OnPropertyChanged()
{
FileSelected();
}
function btnBrowseFile_Click()
{
Form1.inpImageFile.click();
}
</script>
<input id="inpImageFile" title="xxx" style="Z-INDEX: 106; LEFT: 160px; WIDTH: 87px; POSITION: absolute; TOP: 62px; HEIGHT: 24px"
onpropertychange="inpImageFile_OnPropertyChanged() " tabIndex="1" type="file" size="1" name="filepath" runat=server>
<input id="btnBrowseFile" title="Browse For File" style="Z-INDEX: 138; LEFT: 248px; WIDTH: 24px; POSITION: absolute; TOP: 61px; HEIGHT: 26px" type="button" value="..." onclick="btnBrowseFile_Click()" runat="server">
Many thanks
|
|

November 4th, 2003, 04:07 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hmmm, tricky. It seems that the file box causes a post back, even before its value has been set correctly by the client side JavaScript. Is that correct?
How about you use the onchange handler instead of the onpropertychange handler? Would that work?
Alternatively, how about adding the Page.GetPostBackEventReference call inside the JavaScript method that invokes the file.click() method?
I haven't tried any of these solutions out (can't access a .NET environment at the moment), but it may be worth trying it out.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 5th, 2003, 05:12 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply.
I don't get a postback from the file box either before or after the file has been selected.
There is no onchange event - the only event that seems to fire on file selection is onpropertychange.
Could you please explain how I would go about adding the Page.GetPostBackEventReference call inside the JavaScript method? I've only ever called it from server side code.
Cheers
|
|

November 5th, 2003, 03:55 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am not to familiar with Page.GetPostBackEventReference.
What you could do, is see what this methods outputs as JavaScript, and then put that in the JavaScript for the page.
I wish Peter was here. Maybe he has an answer. Peter?? ;)
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 5th, 2003, 04:18 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Investigating.....
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 5th, 2003, 04:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
This *is* truly weird. Take a look at this:
Code:
<html>
<head>
<title>TestUpload</title>
<script language="JavaScript" type="text/javascript">
function HandleFileButtonClick()
{
document.Form1.txtFile.click();
document.Form1.txtFakeText.value = document.Form1.txtFile.value;
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<input type="file" id="txtFile" runat="server" style="display:none;">
<input type="text" name="txtFakeText" readonly="readonly" />
<input type="button" value="Browse" onclick="HandleFileButtonClick();" />
<asp:Button id="btnSubmit" runat="server" Text="Upload" />
</form>
</body>
</html>
When I run this page, browse for a file, and then click the Upload button, it doesn't even upload (I can't see the page refreshing in the browser's progress bar). I have to click it a second time, and then the Uploaded file is empty. Well, there is a file (PostFile != null) but when I save it, I get a zero bytes file
Very strange. This must be a bug somewhere.
Also investigating.....
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 5th, 2003, 04:50 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Woah! I was doing the exact same thing, and got the same result!.... VERY strange.
It's almost like the asp:button is doing a reset, then doing the submit.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 7th, 2003, 01:22 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Look here:
http://www.experts-exchange.com/Web/..._20398679.html
For some reason, they found it necessary to create an additional form on the page for the Submit button...
-Van
-Van
(Old dog learning new tricks...)
|
|

November 7th, 2003, 08:49 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That sounds like the perfect solution, as I need to use an image button anyway. I'll give it a try
Thanks for your help guys
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Change Caption HtmlInputFile |
Israr |
ASP.NET 1.0 and 1.1 Professional |
4 |
November 8th, 2006 02:32 AM |
| HtmlInputFile |
g_vamsi_krish |
ASP.NET 1.0 and 1.1 Basics |
2 |
July 25th, 2006 06:40 AM |
|
 |