webmethod结果中的文本框值不变

时间:2017-09-15 05:31:38

标签: c# jquery webmethod

这里Webmethod正确返回值,标签值根据条件改变,但txtusername的值没有改变

<div class="col-sm-6">
<p style="margin: 0 0 5px 0;"><b>User Name</b>&nbsp;<span class="pull-right">
    <asp:Label ID="usernamelbl" Font-Size="X-Small" runat="server"></asp:Label></span></p>
<asp:TextBox ID="txtUserName" CssClass="form-control" runat="server" placeholder="Enter UserName" 
OnChange="CheckUserName(this)"></asp:TextBox>
</div>

Jquery的

 function CheckUserName(oName) {
                PageMethods.UserNameChecker(oName.value, OnSucceeded);
            }
            function OnSucceeded(result, userContext, methodName) {
                lbl = document.getElementById('<%=usernamelbl.ClientID %>');
                lbl1 = document.getElementById('<%=txtUserName.ClientID %>');
                if (methodName == "UserNameChecker") {
                    if (result == true) {
                        lbl.innerHTML = 'Try Another Username';
                        lbl.style.color = "red";
                        $('<%=txtUserName.ClientID %>').val('');
 lbl1.style.color = "Blue";
                    }
                    else {
                        lbl.innerHTML = '';
                    }
                }
            }

这可行(lbl1.style.color =“Blue”;)很好,但值没有改变。我也尝试lbl1.innerHTML ='';但失败了  请帮帮我

1 个答案:

答案 0 :(得分:0)

使用

public zvol_name_array: Array<String> = [];
public zvol_object: Array<object> = [];

ngOnInit() {
    function find_nested_zvol(zvol: any): String {...snip...}

    let parentThis = this;
    this.rest.get(this.volume_resource_name , {}).subscribe((res) => {
        for(let zvol_list of res.data) {
            parentThis.zvol_name_array.push(zvol_list['vol_name']);
        }
    });
}

对于你的写作方式,你没有充分利用lbl1.value = "something"

而不是

jquery

你可以写成

lbl1 = document.getElementById('<%=txtUserName.ClientID %>');

lbl1 = $('input[id$="txtUserName"]'); 表示以

结尾的ID

然后您可以使用id$填充它

你可以放弃以下脚本,

lbl1.val("something")

如果您坚持使用它,则需要添加

$('<%=txtUserName.ClientID %>').val('');