无法回复asp.net按钮 [英] unable to do post back for asp.net button
本文介绍了无法回复asp.net按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有asp.net按钮
< div >
< div >
<% - < asp:FileUpload ID = FileUpload2 runat = server宽度= < span class =code-string> 290px /> - %>
< asp:FileUpload ID < /跨度> = FileUpload2 runat = server 宽度 = 330px 字体大小 = 12px / >
< < span class =code-leadattribute> / div >
< div id = divspanError class = strttxt style = font-size:12px; font-family:Calibri;宽度:330px;身高:15px; text-align:left; >
<% - < span class = strttxt style = padding-left:0px; padding-top:1px; color:red; font-size:14px; font-family:Calibri; id = spanError runat = server > < / span > - %>
< asp:RequiredFieldValidator ID = RequiredFieldValidator4 runat = < span class =code-keyword> server
< span class =code-attribute> < span class =code-attribute> ErrorMessage = 请选择您的txt文件 CssClass = validationCss ValidationGroup = 我 ForeColor = 红色 字体大小 = 12px
< span class =code-attribute> ControlToValidate = FileUpload2 > < / asp:RequiredFieldValidator >
< / div >
< / div >
< ; asp:按钮 ID =btnUploadrunat =serverCssClass =trnsferpopupbtnValidationGroup =IOnClick =btnUpload_Click
Text =UploadStyle =width:180px; 身高: 35px/>
问题是,当我点击该按钮回发没有发生时,按钮点击事件不会触发,当我查看源它在按钮上显示我的页面点击
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions( btnUpload,,true,I,,false,false))
解决方案
嗨aassaahh,
你的代码中的一切都很好。有2个条件
1.如果你在浏览按钮中选择任何东西然后,如果您点击按钮,它将返回一个回复以及调用 btnUpload_Click 方法。
2.如果您在浏览中没有选择任何内容按钮然后如果你点击按钮它什么都不做。
这是因为你使用了 ValidationGroup =I 。
prot已经 void Page_Load( object sender,EventArgs e)
{
if (IsPostBack)
{
// 此代码块将在页面回发时显示。
}
}
< blockquote>似乎是客户端验证导致问题。通过删除按钮的验证组或使用CausesValidation =false来测试它。确认您可以进行必要的更改以进行验证。
在aspx页面和aspx.cs页面上使用
onclick =btnUpload_Click使用
受保护 void btnUpload_Click( object sender,EventArgs e)
{
}
Hi, i have asp.net button as
<div>
<div>
<%-- <asp:FileUpload ID="FileUpload2" runat="server" Width="290px" />--%>
<asp:FileUpload ID="FileUpload2" runat="server" Width="330px" Font-Size="12px" />
</div>
<div id="divspanError" class="strttxt" style="font-size: 12px; font-family: Calibri; width: 330px; height: 15px; text-align: left;">
<%-- <span class="strttxt" style="padding-left: 0px; padding-top: 1px; color:red;font-size:14px;font-family:Calibri;" id="spanError" runat="server"></span>--%>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="Please Select your txt file" CssClass="validationCss" ValidationGroup="I" ForeColor="Red" Font-Size="12px"
ControlToValidate="FileUpload2"></asp:RequiredFieldValidator>
</div>
</div>
<asp:Button ID="btnUpload" runat="server" CssClass="trnsferpopupbtn" ValidationGroup="I" OnClick="btnUpload_Click"
Text="Upload" Style="width: 180px; height: 35px" />
the problem is that when i click on that button postback is not happening ,button click event does not fire ,when i view source the page it show me on the button onclick
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnUpload", "", true, "I", "", false, false))
解决方案
Hi aassaahh,
Every thing is fine in your code. There are 2 condition
1.If you select anything in the Browse Button then if you will click on the button it will do a post back as well as call the btnUpload_Click method.
2.If you select nothing in the Browse Button then if you will click on the button it will do nothing.
It is happening because you have used a ValidationGroup="I" .
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { //This code block will when the page will be posted back. } }
Seems to be the client validation is causing the issue. Test it by removing the validation group for the button or by using CausesValidation="false". After confirming that you can make necessary change for validation.
use
onclick="btnUpload_Click" on aspx page and on aspx.cs page use
protected void btnUpload_Click(object sender, EventArgs e) { }
这篇关于无法回复asp.net按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文