Forums » .NET » JQuery »

How to fire jQuery event after postback?


Posted Date: 07 Aug 2013      Posted By:: LuckyIBM     Member Level: Gold    Member Rank: 1339     Points: 5   Responses: 1



Hi friends,
I have a DashBoard Page in ASP.Net with C#, Which contains a timer control wchich call page every 25 Sec. I have an image button for any new alert.
First time when page Load it works. It means clicking on image button, its dril down a DIV & LINK button, but it works only once, after Page refresh (By timer control), it does not work.
Here is inline code.
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">

<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>

<ContentTemplate>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">


$("#<%=this.bellIMG.ClientID %>").click
(
function (event) {
//event.preventDefault()

//$("#mydiv").css({ visibility: "visible" })
//$("#mydiv").fadeToggle()
$("#<%=this.mydiv.ClientID %>").css({ visibility: "visible" })
$("#<%=this.mydiv.ClientID %>").fadeToggle()
}
)


</script>

<caption>
<div id="mydiv" runat="server" style="width:150px height:350px background-color:#d2edca z-index:1 position: absolute visibility:hidden margin-left:110px overflow:scroll" >
</div>

</ContentTemplate>
</asp:UpdatePanel>

<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="25000"></asp:Timer>

And CODE BEHIND Code is......

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BIND_BELL()
}
}

private void BIND_BELL()
{
DataSet DS = new DataSet()
lblTKTING.Text = "Ticketing Alert:"
try
{
if (con.State == ConnectionState.Closed)
{
con.Open()
}
string QRY = "SELECT DUTY_ID FROM DASHBOARD "
OracleDataAdapter ODA = new OracleDataAdapter(QRY, con)
ODA.Fill(DS)
if (DS.Tables[0].Rows.Count > 0)
{
bellIMG.Visible = true
for (int i = 0 i < DS.Tables[0].Rows.Count i++)
{
LinkButton Bell_lnk = new LinkButton()
Bell_lnk.ID = "Bell_lnk_" + i.ToString()
Bell_lnk.Text = DS.Tables[0].Rows[i]["DUTY_ID"].ToString()

mydiv.Controls.Add(Bell_lnk)

//Bell_lnk.Attributes.Add("onclick", "BELL_LNK_click(" + Bell_lnk.Text + ")")

Bell_lnk.Attributes.Add("onclick", "BELL_LNK_click(" + Bell_lnk.Text + ")" + this.Page.ClientScript.GetPostBackEventReference(Bell_lnk, "").ToString())
}
}
else
{
bellIMG.Visible = false
lblTKTING.Text = "Ticketing Alert: 0"
}
}
catch (Exception ex)
{
//Response.Write(ex.Message)
}
finally
{
con.Close()
DS.Clear()
}
}


protected void Timer1_Tick(object sender, EventArgs e)
{
BIND_BELL()
}





Are you looking for information on jQuery? Want to know how to fire jQuery event after postback? Read this thread to learn more about jQuery with examples.

Responses

#725249    Author: Rajan Patekar      Member Level: Gold      Member Rank: 525     Date: 08/Aug/2013   Rating: 2 out of 52 out of 5     Points: 3

Hi LuckyIBM,
This issue occur because your placement of the code for event fired gets wrong after page gets refreshed.
For resolving this issue write your event as follows:

$(document).on("click","id or class of your image button",function(){write your respective code});

This function scans entire document for the particular item you provided and binds provided event.
Remember write this code outside of document.ready function.


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India