单击按钮时进度条不显示 - c#

我有一个Fileupload控件,当我单击上传按钮时,我只是想显示图像,即进度条或加载gif图像。我通过javascript进行了尝试,但无法显示该图片。我希望在文件上传之前显示该图像。

这是我的aspx代码:

<form id="form1" runat="server">
    <div class="transbox" id="mainbk" runat="server" style="position:absolute; top:0px; left:0px; width: 100%; height: 100%;" >
            <fieldset style="width:51%; margin-left:300px;font-family:'Palatino Linotype';font-size:large">
            <legend style="color:white;font-family:'Palatino Linotype'">Upload Video Files</legend>
                <asp:FileUpload EnableViewState="true" runat="server" ID="UploadImages" style="background-color:white; position:relative; font-family:'Palatino Linotype'; font-size:medium" Width="500px" AllowMultiple="false"/>
                <asp:RequiredFieldValidator ID="reqFile" runat="server" ControlToValidate="UploadImages" ErrorMessage="Select a File" style="color:red;position:absolute"></asp:RequiredFieldValidator><br />
                <asp:Label Text="Description:" runat="server" ID="lbldes" style="font-family:'Palatino Linotype';position:absolute; margin-top:10px; font-size:large;color:white" ></asp:Label>
                <asp:TextBox id="txtdes" runat="server" TextMode="MultiLine" Height="60px" style="margin-top:10px;margin-left:195px;" Width="300px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="txtreq" runat="server" ControlToValidate="txtdes" ErrorMessage="Description Required" style="color:red;position:absolute;margin-top:20px;" ></asp:RequiredFieldValidator><br />

                <asp:Button runat="server" ID="uploadedFile" style="position:relative; font-family:'Palatino Linotype'; font-size:medium; width: 112px; height: 29px;" Text="Upload" UseSubmitBehavior="true" OnClick="uploadedFile_Click"/>
                <asp:image id="loading_img" runat="server" style="Display:none;position:absolute;margin-top:-20px;margin-left:200px;" src="../Images/Other Images/waiting.gif" />
            </fieldset>
     </div>
    </form>

这是我的javascript:

 <script type="text/javascript">
        $('#uploadedFile').click(function () {
            $('#loading_img').show(); // Show image
            return true; // Proceed with postback
        });
    </script>

这是aspx.cs页面中按钮上载文件的我的点击事件。

protected void uploadedFile_Click(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
             string fileExt = Path.GetExtension(UploadImages.FileName).ToLower();
             if (fileExt == ".flv" || fileExt == ".avi" || fileExt == ".mp4" || fileExt == ".3gp" || fileExt == ".mov" || fileExt == ".wmv" || fileExt == ".mpg" || fileExt == ".asf" || fileExt == ".swf")
             {
                try
                {

                    filepath = Server.MapPath("~/Videos/" + UploadImages.FileName);
                    UploadImages.PostedFile.SaveAs(filepath);
                    vurl=UploadImages.FileName.ToString();
                    newpath = "Images//Video_Thumbs//" + createvidImage(filepath);
                    al = txtdes.Text.ToString();
                    id += 1;
                    string Insert = "Insert into video (vid,videoname,videourl,vidthumb) values (@id,@alter,@vrl,@IMAGE_PATH)";
                    SqlCommand cmd = new SqlCommand(Insert, con);
                    cmd.Parameters.AddWithValue("@IMAGE_PATH", newpath.ToString());
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.Parameters.AddWithValue("@alter", al);
                    cmd.Parameters.AddWithValue("@vrl", vurl);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Video Uploaded!!');", true);

                        txtdes.Text = "";
                    }
                    catch (Exception e1)
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('" + e1.Message.ToString() + "!!');", true);
                    }
                }
                catch (Exception ex)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('" + ex.Message.ToString() + "!!');", true);
                }
            }
        }
    }

请帮我用javascript或C#做到这一点。

参考方案

此处的问题是<asp:Button/>标记(以及所有asp标记)在页面中的呈现方式。如果右键单击并检查该元素,您会看到其ID实际上不是'uploadedFile',而是可能类似'ctl00_uploadedFile'之类的结果,因此,您的jQuery选择器找不到该元素。我建议以下两件事之一:

1)检查页面,查看实际呈现的元素被命名为什么,然后相应地更新jQuery。

2)使用嵌入式C#代码段提取ID。例如,您可以将$('#uploadedFile')替换为$('#' + '<%=uploadedFile.ClientID%>')。其中的<%%>部分将评估为C#,并将ClientID属性(即在页面上呈现的id值)插入jQuery选择器。

编辑:显然我对<asp:Button/>标记弄错了,它们使用不变的name属性而不是id属性进行渲染。您想要的uploadFile按钮的选择器是$('input[name="uploadedFile"]')

代码未在服务器目录php中创建文件 - php

我正在尝试使用以下代码将新文件写入服务器error_reporting(E_ALL); ini_set('display_errors', 1); if($_SERVER['REQUEST_METHOD'] == "POST") { $html = $_POST['html'];…

故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” - php

我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…

CodeIgniter更新查询被执行两次 - php

我正在使用CodeIgniter 2.2。每次访问页面时,我都必须用+1更新数据库。代码可以工作,但是每次都会增加+2。示例:如果是total views=2,则在单击页面后total views应该是3,但是数据库中的值是4。我确定我在控制器中仅调用一次模型add_one_to_view_image。控制者 function view(){ $view_i…

当<form>'.submit'函数被覆盖时(使用Ajax)将数据获取到php吗? - javascript

我已覆盖此网页上表单的.submit函数,因为该网页已加载在“ index.php”中的#mainContent内,并且我希望“提交”按钮仅替换此#mainContent。我正在尝试将数据从此表单获取到.php文件,以便对数据库进行查询(或简单地回显已填充的变量,以指示已传递数据)。我是AJAX的新手。有人可以向我解释如何将数据传递到.php文件,或者指向要…

jQuery不起作用 - php

我正在使用带有ajax的jquery。有时,给出错误$未定义。这是我的代码:<script language="javascript" type="text/javascript"> var base_path="<? echo $this->baseUrl().'/…