By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,363 Members | 1,732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,363 IT Pros & Developers. It's quick & easy.

File Upload and doPostBack

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.