ASP.NET - How to retrive a variable from a Sub with VB? -
i using runat
command within public sub in .aspx page follows:
<% dim haslabel %> <script runat="server"> public sub button1_click(byval sender object, _ byval e system.eventargs) if fileupload1.hasfile dim fileext string fileext = system.io.path.getextension(fileupload1.filename) if (fileext = ".docx" or fileext = ".doc") try fileupload1.saveas("path_to_file" & _ fileupload1.filename) label1.text = "<div class='centertext'>statement received, thank you!<br /><br />file name: " & _ fileupload1.postedfile.filename & "<br>" & _ "file size: " & _ fileupload1.postedfile.contentlength & " kb</div>" catch ex exception label1.text = "error: " & ex.message.tostring() end try else label1.text = "only word document files allowed (.doc, .docx)." end if else label1.text = "you have not specified file." end if haslabel = label1.text end sub </script>
later on down page, i'd able check haslabel
content , if it's not empty, output on page, else, output form again, this:
<body> <form id="form1" runat="server"> <% if haslabel <> "" %> <div class="centertext"><%= haslabel %></div> <% else %> <div> <asp:fileupload id="fileupload1" runat="server" class="file" /><br /> <br /> <asp:button id="button1" runat="server" onclick="button1_click" text="upload file" /> <br /> <asp:label id="label1" runat="server" class="mission_gothic_reg smalltext"></asp:label> </div> <% end if %> </form> </body>
how can accomplish this? right now, error says: name 'haslabel' not declared
basically, trying have happen, is... don't show file upload button if file has been submitted. ofcourse, need change doing when has been uploaded , file type correct. can't find out simple solution knowing if has been uploaded or not within actual asp page. yeah, can output text manipulates tag, how know if label tag has in begin with, in asp.net?
i fixed changing visible property false:
<script runat="server"> protected sub button1_click(byval sender object, _ byval e system.eventargs) if fileupload1.hasfile dim fileext string fileext = system.io.path.getextension(fileupload1.filename) if (fileext = ".docx" or fileext = ".doc") try fileupload1.saveas("full upload file path\" & _ fileupload1.filename) label1.text = "<div class='mission_gothic_reg success'>statement received, thank you!<br />file name: " & _ fileupload1.postedfile.filename & "<br>" & _ "file size: " & _ fileupload1.postedfile.contentlength & " kb</div>" button1.visible = false fileupload1.visible = false catch ex exception label1.text = "<div class='mission_gothic_reg fail'>error: " & ex.message.tostring() & "</div>" end try else label1.text = "<div class='mission_gothic_reg fail'>only word document files allowed (.doc, .docx).</div>" end if else label1.text = "<div class='mission_gothic_reg fail'>you have not specified file.</div>" end if end sub </script>
maybe else.
Comments
Post a Comment