0
當我解僱btn事件時。後刷新頁面,我的RegisterStartupScript驗證asp.net不工作corectly當我使用ScriptManager.RegisterStartupScript時,RequiredFieldValidator不正確工作
protected void btnSumbit_Click(object sender, EventArgs e)
{
NotifyShow("example");
}
public void NotifyShow(string msg)
{
string myScript = string.Format("ShowMessages('{0}','{1}');", msg, "type");
StringBuilder str = new StringBuilder();
str.Append(myScript);
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertJS", str.ToString(), true);
}
這個HTML
<form id="form1" runat="server">
<div id="main">
<asp:TextBox runat="server" ID="txtb1" ValidationGroup="g1" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtb1" Text="not valid" ValidationGroup="g1"></asp:RequiredFieldValidator>
<asp:Button runat="server" ID="btnSumbit" ValidationGroup="g1" OnClick="btnSumbit_Click"/>
</div>
</form>
這個JavaScript
function ShowMessages(messageText, type) {
var images = "";
document.getElementById("main").innerHTML = document.getElementById("main").innerHTML + "<div id='MessagePopUp' class='" + type + "' title='Error message'>" +"" +"<p id='MessageText' style='direction: rtl; margin: 0px auto; padding: 5px;'>" + messageText + "</p>" +"</div>";
var popUp = document.getElementById("MessagePopUp");
$("#MessagePopUp").show("slide", 1000, function() {
$("#MessagePopUp").hide("slide", 2000, function() {
document.getElementById("main").removeChild(popUp);
});
}).delay(4000);}
你能更具體地說「工作不正常」嗎? –
當我的領域是無效的,再次發射btn,驗證器文本不可見! – ehsanHB
你能粘貼HTML代碼嗎? ShowMessages()函數可能在被調用時尚未定義。 –