viola123
asked on
How to register a javascript function when i am using Ajax update panel?
hi all,
i need to do the following:
1. when every time there is an error message that's need to be displayed on the web page, make the message flashing for a few seconds. i am using a javascript function to achieve it.
2. i am using ajax update panel to control the postback. but i found the javascript function won't work if i am using this update panel. i googled on internet and found i need to register the javascript function, but i don't know where to do this registration and how to do it. can anyone help me to solve this problem?
thanks a lot
viola
i need to do the following:
1. when every time there is an error message that's need to be displayed on the web page, make the message flashing for a few seconds. i am using a javascript function to achieve it.
2. i am using ajax update panel to control the postback. but i found the javascript function won't work if i am using this update panel. i googled on internet and found i need to register the javascript function, but i don't know where to do this registration and how to do it. can anyone help me to solve this problem?
thanks a lot
viola
<head runat="server">
<script src="gen_lib.js" type="text/javascript"></script> //call this javascript file
</head>
<body onload="Init()"> //call this function to display Messages on the form
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ScriptManager1" ScriptMode=Release />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Label ID="status_label" runat="server" CssClass="note_item"></asp:Label> //the message displayed in 'status_label' won't flash at all
<br/>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
--------------------------------
protected void btnSave_Click(object sender, EventArgs e)
{
SetStatus("My Details saved.");
}
private void SetStatus(string msg)
{
status_label.Text="<input type=\"hidden\" id=\"flash_on\" value=\"true\">"+msg;
}
--------------------------------
in my gen_lib.js file:
function Init()
{
var status, exec_elem, ro_elems, ro_elem, objs, i, menu_id;
//alert("Init...");
status=document.all.status_label;
if (status!=null && document.all.flash_on!=null)
{
if (status!=null && status.innerText!="" && document.all.flash_on.value=="true")
{
Init_Flash("#ffffff", "#00dd00", status);
}
if (status!=null && status.innerText!="" && document.all.flash_on.value=="error")
{
Init_Flash("#ffffff", "#ff0000", status);
}
if (status!=null && status.innerText!="" && document.all.flash_on.value=="warning")
{
Init_Flash("#ffffff", "#999900", status);
}
document.all.flash_on.value="false";
}
//do some other flash job......
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it works great!!!!
what i am doing are:
1. reference the javascript file in ScriptManager
2. register the founction in page_load event
thanks heaps
Open in new window