PostBack上的Asp.net文本框为空

时间:2017-05-12 11:43:58

标签: c# asp.net button textbox postback

我正在尝试创建一个登录页面。每当我点击登录按钮用户名时,文本框的文字就会变空。
我试过了:

  1. 使用Updatepanel无法正常工作
  2. OnClientClick-它不会触发OnClick事件
  3. 我尝试通过字符串获取值usrnm = Page.Request.Form [" username"]。ToString();但它给出了空值
  4. 我尝试将AutoPostBack =" true"在文本框上
  5. 继承人:markUp:

    <label for="username">Username</label>
    <%--<input type="text" name="Uname" id="username"/>--%>
    <asp:TextBox ID="txtusrnm" runat="server" AutoPostBack="true"/>
    </div>
    <div class="form-group">
        <label for="password">Password</label>
        <input type="password" name="Pname" id="password">
    </div>
    <div class="form-group"><a href="#">Forgot password?</a></div>
    <hr class="hr-sm hr-stroke" />
    <div class="form-group">
       <%--<input id="btnlogin" type="button" class="btn btn-primary btn-wide" value="Login" runat="server" onserverclick="btnlogin_ServerClick"  >--%>
       <asp:Button ID="btnLogin" runat="server" Text="Login" class="btn btn-primary btn-wide" OnClick="btnLogin_Click" UseSubmitBehavior="false" EnableViewState="true" />
    

1 个答案:

答案 0 :(得分:1)

我可以解决我的问题,我在文本框中有AutoPostBack='true'所以只是删除了UseSubmitBehavior="false" EnableViewState="true"并将CausesValidation="False"替换为<asp:TextBox ID="txtusrnm" runat="server"/> ,现在运行正常。

文本框:

 <asp:Button ID="btnLogin" runat="server" Text="Login" class="btn btn-primary btn-wide" OnClick="btnLogin_Click" CausesValidation="False"/>

和按钮:

var films = [

{
    movie: "fast and the furious",
    rating: 4,
    seen: true
},
{
    movie:"13 reasons why",
    rating: 5,
    seen: true


}, 
{
    movie:"beaty and the beast",
    rating: 4,
    seen: false
}

];


films.forEach(function(film){
var result = "You have ";
if(film.seen) {
    result += "watched ";
} 
else{
    result += "not seen ";
}
result += "\"" + film.movie + "\" - ";
result += film.rating + " stars";

console.log(result);

});

由于