我所拥有的是一个ASP.NET 2.0 Web应用程序,允许用户上传.CSV
html输入类型是提交。
我想知道是否有一种方法可以更新我的UpdatePanel,它位于输入下方,在我的onserverclick方法发生之前显示一点“Processing”.gif。
我已尝试在该事件开始时引用另一个事件,以及其他方法,但我没有运气。根据我的理解,该方法需要在我的UpdatePanel刷新之前完成。
以下是你们的一些代码
<div class=" content-div">
<input type="file" id="File1" name="File1" runat="server" />
Select file Type:
<asp:DropDownList ID="ddlfileupload" runat="server">
<asp:ListItem>CSV</asp:ListItem>
</asp:DropDownList>
</div>
<div class=" content-div">
<input type="submit" id="Submit1" value="Upload File" runat="server" onserverclick="Submit1_ServerClick"
style="border-top-style: groove; border-right-style: groove; border-left-style: groove;
border-bottom-style: groove" />
<asp:Label ID="Label6" runat="server" BorderColor="White" BorderStyle="None" Font-Bold="True"
Visible="False"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
以及代码背后的事件:
protected void Submit1_ServerClick(object sender, EventArgs e)
{
AddProcessGif();
// Logic from submit button here that uploads .csv
}
AddProcessGif()是一种以编程方式添加我的.gif和东西的方法。它有效,我看到它火了,但只有在我上传完成后才会失败。
我这里没有一个编写得很好的应用程序,而且我对ASP.NET很新,所以我不确定如何有效地创建一个进度条或类似的东西。
任何建议都将不胜感激
答案 0 :(得分:1)
您可以从javascript调用c#服务器端方法。 你需要做的是在你的aspx页面中添加一个scriptmanaget并将EnablePageMethods设置为true。
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
您的C#方法也必须是[WebMethod],如
[WebMethod]
public static string DoSomething(string str1, string str2)
{
string result = "This is concatenation of " + str1 + " and " + str2 + "'.";
return result;
}
然后在你的aspx页面中添加javascript函数来调用C#服务器端的DoSomething方法
<head runat="server">
<title></title>
<script type="text/javascript">
function DoSomthing() {
var str1 = document.getElementById('<%=txtstr1.ClientID %>').value;
var str2 = document.getElementById('<%=txtstr2.ClientID %>').value;
//Here we call server side methode
PageMethods.DoSomeThing(str1, str2, onSucess, onError);
function onSucess(result) {
alert(result);
}
function onError(result) {
alert('Something wrong.');
}
}
</script>
希望有所帮助