I added a web user control and created a function in jquery at client side named “ButtonClick” on web user control. And calling this method from code behind using ScriptManager.RegisterStartupScript in loop .
But it runs only one time, while it should run loop times.
Please help me……
Code sample is here
var q = (from p in obj.Pinny_ShowOffer where (p.OfferID == objOffer.OfferID) select p).ToList();
if (q.Count > 0)
{
Rdbtnoffersetup.Items.FindByValue("2").Selected = true;
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowDIv", "ShowDiv(2,2);", true);
Int32 k = 0;
for (Int32 i = 0; i < q.Count; i++)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ButtonClick",
"ButtonClick('btn" + q[i].Weekday + "','" + q[i].Weekday + "');", true);
if (q[i].StartTime == "07:00" && q[i].EndTime == "11:00")
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "select value", "SelectValueoFDropDown('drpStart" + q[i].Weekday + k + "','1');", true);
}
k++;
}
}
The reason it’s only firing once is because you’re duplicating they key
ButtonClickin yourRegisterStartupScriptcall.From the documentation:
You could trying something like this instead to keep it unique: