473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

File Upload and doPostBack

I am trying to cause the uplaod button, id="Upload",when clicked, to exectue the onClick event for Button1, id="Button1".

<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server"> </asp:Button>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server" Visible="false">

in the code behind file I am using the following code to add the __doPostBack to the Upload button:

protected void Page_Load(object sender, EventArgs e)
{
Upload.Attributes.Add("onClick", "__doPosback(" + Button1.ToString() + ",'')");
}

When I run this in IE the javascript throws the error:
'System' is undefined.

When I use the source view, the line which causes the error is as follows:
<input type="submit" name="Upload" value="Upload file" onclick="__doPosback(System.Web.UI.WebControls.But ton,'');" id="Upload" />

What am I doing wrong? Any help is greatly appreciated.

Thanks,
M. Vuksanovic.

Jun 26 '06 #1
4 9652
Hi Marko,

The first thing I noticed was a typographical error:

__doPosback

Shouldn't there be a "t" in there?

Maybe it isn't that problem, but worth a check.

Ken
Microsoft MVP [ASP.NET]

"Marko Vuksanovic" <ma*************@hotmail.com> wrote in message
news:D3**********************************@microsof t.com...
I am trying to cause the uplaod button, id="Upload",when clicked, to exectue
the onClick event for Button1, id="Button1".

<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server">
</asp:Button>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server"
Visible="false">

in the code behind file I am using the following code to add the
__doPostBack to the Upload button:

protected void Page_Load(object sender, EventArgs e)
{
Upload.Attributes.Add("onClick", "__doPosback(" + Button1.ToString() +
",'')");
}

When I run this in IE the javascript throws the error:
'System' is undefined.

When I use the source view, the line which causes the error is as follows:
<input type="submit" name="Upload" value="Upload file"
onclick="__doPosback(System.Web.UI.WebControls.But ton,'');" id="Upload" />

What am I doing wrong? Any help is greatly appreciated.

Thanks,
M. Vuksanovic.
Jun 26 '06 #2

"Ken Cox [Microsoft MVP]" <BA**********@newsgroups.nospam> wrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Ken,

I've corrected taht, and the error is still the same.
Hi Marko,

The first thing I noticed was a typographical error:

__doPosback

Shouldn't there be a "t" in there?

Maybe it isn't that problem, but worth a check.

Ken
Microsoft MVP [ASP.NET]

"Marko Vuksanovic" <ma*************@hotmail.com> wrote in message
news:D3**********************************@microsof t.com...
I am trying to cause the uplaod button, id="Upload",when clicked, to
exectue the onClick event for Button1, id="Button1".

<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server">
</asp:Button>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server"
Visible="false">

in the code behind file I am using the following code to add the
__doPostBack to the Upload button:

protected void Page_Load(object sender, EventArgs e)
{
Upload.Attributes.Add("onClick", "__doPosback(" + Button1.ToString() +
",'')");
}

When I run this in IE the javascript throws the error:
'System' is undefined.

When I use the source view, the line which causes the error is as follows:
<input type="submit" name="Upload" value="Upload file"
onclick="__doPosback(System.Web.UI.WebControls.But ton,'');" id="Upload" />

What am I doing wrong? Any help is greatly appreciated.

Thanks,
M. Vuksanovic.

Jun 26 '06 #3
you have several errors

1) spelled "__doPostback" wrong
2) left quotes off the parameter value
3) passed the type name rather than the client id
4) did not cancel the original postback, so when fixed will postback twice.
5) "__doPostback" is only defined if an autoback control is on the page.

try:

Upload.Attributes.Add("onClick", "__doPostback("' + Button1.ClientID + '",'');return false");
GetPostbackClientEvent( Button1,"");
-- bruce (sqlwork.com)

"Marko Vuksanovic" <ma*************@hotmail.com> wrote in message news:D3**********************************@microsof t.com...
I am trying to cause the uplaod button, id="Upload",when clicked, to exectue the onClick event for Button1, id="Button1".

<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server"> </asp:Button>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server" Visible="false">

in the code behind file I am using the following code to add the __doPostBack to the Upload button:

protected void Page_Load(object sender, EventArgs e)
{
Upload.Attributes.Add("onClick", "__doPosback(" + Button1.ToString() + ",'')");
}

When I run this in IE the javascript throws the error:
'System' is undefined.

When I use the source view, the line which causes the error is as follows:
<input type="submit" name="Upload" value="Upload file" onclick="__doPosback(System.Web.UI.WebControls.But ton,'');" id="Upload" />

What am I doing wrong? Any help is greatly appreciated.

Thanks,
M. Vuksanovic.

Jun 26 '06 #4
Thank you bruce,

I am trying to implement an upload progress indicator using atlas, using the following workaround:
http://forums.asp.net/thread/1321664.aspx

This is the code in FileUpload.apsx file is as follows:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title> drag </title>
</head>
<body>
<form id="f1" enctype="multipart/form-data" runat="server">
<h4>Select a file to upload:</h4>
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

<atlas:UpdatePanel ID="upResults" runat="server" Mode="conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="Upload" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server"> </asp:Button>
</ContentTemplate>
</atlas:UpdatePanel>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server"></asp:Button>
<br /><br />
<atlas:UpdateProgress ID="uprProgress" runat="server">
<ProgressTemplate>
<img src="images/animated_loading.gif" /> Uploading....
</ProgressTemplate>
</atlas:UpdateProgress>

</form>
</body>
</html>

The relevant code from the code behind file is:

protected void Page_Load(object sender, EventArgs e)
{
( * ) Upload.Attributes.Add("onClick", "__doPostBack('" + Button1.ClientID + "','');return false;");
ClientScript.GetPostBackEventReference(Button1, "");
}

protected void UploadButton_Click(object sender, EventArgs e)
{
String savePath = @"C:\Temp\uploads\";
if (this.FileUpload.HasFile)
{
String fileName = FileUpload.FileName;
savePath += fileName;
FileUpload.SaveAs(savePath);
}
else
{
}
}

The problem is, in the line of code in the Page_Load Function, if I use the "onClick" the (ProgressTemplate is not displayed), if I use the "onClientClick" the ProgressTemplate is correctly displayed but the file is not uploaded.

Any idea what might be wrong?

Many thanks,
Marko

"bruce barker (sqlwork.com)" <b_*************************@sqlwork.com> wrote in message news:%2****************@TK2MSFTNGP02.phx.gbl...
you have several errors

1) spelled "__doPostback" wrong
2) left quotes off the parameter value
3) passed the type name rather than the client id
4) did not cancel the original postback, so when fixed will postback twice.
5) "__doPostback" is only defined if an autoback control is on the page.

try:

Upload.Attributes.Add("onClick", "__doPostback("' + Button1.ClientID + '",'');return false");
GetPostbackClientEvent( Button1,"");
-- bruce (sqlwork.com)

"Marko Vuksanovic" <ma*************@hotmail.com> wrote in message news:D3**********************************@microsof t.com...
I am trying to cause the uplaod button, id="Upload",when clicked, to exectue the onClick event for Button1, id="Button1".

<asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
<asp:Button id="Upload" Text="Upload file" runat="server"> </asp:Button>

<asp:Button id="Button1" OnClick="UploadButton_Click" runat="server" Visible="false">

in the code behind file I am using the following code to add the __doPostBack to the Upload button:

protected void Page_Load(object sender, EventArgs e)
{
Upload.Attributes.Add("onClick", "__doPosback(" + Button1.ToString() + ",'')");
}

When I run this in IE the javascript throws the error:
'System' is undefined.

When I use the source view, the line which causes the error is as follows:
<input type="submit" name="Upload" value="Upload file" onclick="__doPosback(System.Web.UI.WebControls.But ton,'');" id="Upload" />

What am I doing wrong? Any help is greatly appreciated.

Thanks,
M. Vuksanovic.

Jun 26 '06 #5

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

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
0
by: valmir cinquini | last post by:
Hi, I've noticed that a doPostBack call always cause the position of the page goes up to the top of the page, after round trip. I'd like to place the page at original position where it was...
3
by: Mad Scientist Jr | last post by:
I have some javascript I would like to run after a doPostBack occurs: onchange="javascript:__doPostBack('Text1','');" The doPostBack is being added dynamically by .NET when it renders the...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
0
by: masoud bayan | last post by:
Hi , I used your suggested code to replace doPostBack in my application, but it seems window.onbeforeunload is called before, window.__doPostBack, so it can not change the condition for showing...
2
by: DSipp | last post by:
First, I am not a developer. My company works with a partner. This partner has a web app that we interact with. All of my systems can connect and login to this site. When we select an issue link,...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.