我有一個aspx頁面,其中包含2個用戶控件當從usercontrol調用jquery函數不起作用
UC1:編輯頁面 - 它有用於編輯或數據輸入的字段。
UC2:通知頁 - 這與jQuery函數一個簡單的消息框
在我的aspx我有這樣的功能:
public void ShowMessage(string status, string message)
{
Notification1.Message = message; //this is my user control UC2
Notification1.Status = status;
Notification1.DataBind();
}
現在,當我的aspx頁面需要顯示一條消息,該工作正常,但是當我想讓用戶控件1顯示一條消息(無效字段或錯誤的數量)時,它不會執行任何操作。現在它被調用,但jquery只是不反應。
在UC2 -notification用戶控制這個是我:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script>
<script type="text/javascript">
function showMsg(classname) {
$("#MsgBox").attr('class', classname);
$("#MsgBox").show().delay(5000).fadeOut();
}
</script>
<div id="MsgBox" class="info"><asp:Label ID="lblMessage" runat="server" /></div>
代碼隱藏
public string Status{ get; set; }
public string Message { get; set; }
public override void DataBind()
{
if (Message != string.Empty)
{
lblMessage.Text = Message;
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showMsg('" + Status + "');", true);
}
}
,這是我如何調用從用戶控制功能給aspx頁面:
((myaspxpage)this.Page).ShowMessage("error", "This is my error message.");
任何幫助將非常感激!如果需要進一步的細節,請讓我知道..在此先感謝。
**編輯:我試圖把我的編輯頁面中的jQuery和消息框,看看它是否會以這種方式工作,它並沒有因此,似乎jquery不能很好地在一個usercontrol?
你確認你的jQuery源被發現? – 2012-07-06 15:39:36
@Jeff我不會在我的瀏覽器控制檯得到任何錯誤通常,如果沒有找到源,然後它會告訴你嗎? – Andres 2012-07-06 15:45:19