asp.net - i try make upload file using telerik tool with update panel to uplaod file using ajax but it dose not work correctly -
i nead upload file without postback, want use upload panel send data ashx save file
<telerik:radscriptmanager runat="server" id="radscriptmanager1" /> <telerik:radskinmanager id="radskinmanager1" runat="server" showchooser="true" /> <div class="demo-container size-wide no-bg"> <telerik:radajaxpanel id="radajaxpanel1" runat="server" clientevents-onrequeststart="requeststart" loadingpanelid="loadingpanel1"> <div class="uploadpanel"> <div class="leftpanel"> <div class="controls first"> <span class="label">nick</span> <br /> <telerik:radtextbox id="nicktextbox" runat="server" skins ="silk" width="183px"></telerik:radtextbox> </div> <div class="controls"> <span class="label">file(s)</span> <telerik:radupload id="radupload1" runat="server" maxfileinputscount="2" overwriteexistingfiles="false" controlobjectsvisibility="removebuttons" skins="silk" autopostback="true" enabletheming="false"> </telerik:radupload> <telerik:radbutton id="save" runat="server" text="save" skins="silk" onclick="save_click" autopostback="true"> </telerik:radbutton> <asp:button id="buttonsend" enabletheming="false" onclick="buttonsend_click" runat="server" skins="silk" text="save" cssclass="button" ></asp:button> </div> </div> <div class="rightpanel"> <div id="uploadedfilelog" class="uploadedfileclass" runat="server"> no uploaded files yet. </div> </div> </div> </telerik:radajaxpanel> <telerik:radajaxloadingpanel id="loadingpanel1" runat="server" initialdelaytime="0" skin="default"> </telerik:radajaxloadingpanel> <telerik:radcodeblock id="radcodeblock1" runat="server"> <script type="text/javascript" src="js/scripts.js"></script> </telerik:radcodeblock> </div> enter code here code
here make upload file dose not work update panel
public void buttonsend_click(object sender, system.eventargs e) { uploadedfilelog.innerhtml = ""; if (radupload1.uploadedfiles.count > 0) { foreach (telerik.web.ui.uploadedfile postedfile in radupload1.uploadedfiles) { uploadedfilelog.innerhtml += "<b>uploaded file information</b>: <hr />"; uploadedfilelog.innerhtml += "<b>nick name</b>: " + nicktextbox.text; if (!object.equals(postedfile, null)) { string filname = postedfile.filename; string tim = datetime.now.second.tostring() + "-" + datetime.now.minute.tostring() + "-" + datetime.now.hour.tostring() + "-" + datetime.now.day.tostring() + "-" + datetime.now.month.tostring() + "-" + datetime.now.year.tostring(); postedfile.saveas(server.mappath("~/files/test/") + tim + "#" + filname); if (postedfile.contentlength > 0) { uploadedfilelog.innerhtml += string.format("<br /><b>filename</b>: {0}", postedfile.filename); uploadedfilelog.innerhtml += string.format("<br /><b>file size</b>: {0} bytes", postedfile.contentlength); } else { uploadedfilelog.innerhtml += "<br />no uploaded files yet."; } } else { uploadedfilelog.innerhtml += "<br />no uploaded files yet."; } } } } protected void save_click(object sender, eventargs e) { uploadedfilelog.innerhtml = ""; uploadedfilelog.innerhtml += radupload1.uploadedfiles.count.tostring(); if (radupload1.uploadedfiles.count > 0) { foreach (telerik.web.ui.uploadedfile postedfile in radupload1.uploadedfiles) { uploadedfilelog.innerhtml += "<b>uploaded file information</b>: <hr />"; uploadedfilelog.innerhtml += "<b>nick name</b>: " + nicktextbox.text; if (!object.equals(postedfile, null)) { string filname = postedfile.filename; string tim = datetime.now.second.tostring() + "-" + datetime.now.minute.tostring() + "-" + datetime.now.hour.tostring() + "-" + datetime.now.day.tostring() + "-" + datetime.now.month.tostring() + "-" + datetime.now.year.tostring(); postedfile.saveas(server.mappath("~/files/test/") + tim + "#" + filname); if (postedfile.contentlength > 0) { uploadedfilelog.innerhtml += string.format("<br /><b>filename</b>: {0}", postedfile.filename); uploadedfilelog.innerhtml += string.format("<br /><b>file size</b>: {0} bytes", postedfile.contentlength); } else { uploadedfilelog.innerhtml += "<br />no uploaded files yet."; } } else { uploadedfilelog.innerhtml += "<br />no uploaded files yet."; } } } }
uploading files requires full postback.
also, try using radasyncupload, radupload has been obsolete 2 years now.
you can read on both things here http://www.telerik.com/help/aspnet-ajax/asyncupload-overview.html
here example:
<asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <telerik:radasyncupload runat="server" id="radasyncupload1"></telerik:radasyncupload> <asp:button id="button1" text="work files" onclick="button1_click" runat="server" /> </contenttemplate> </asp:updatepanel>
and
protected void button1_click(object sender, eventargs e) { foreach (uploadedfile file in radasyncupload1.uploadedfiles) { file.saveas(server.mappath("~/images/" + file.getname()), true); } }
of course, add more complex logic here. checking existing files, creating proper file names, handling user permissions, etc.
Comments
Post a Comment