films-araigun Rotating Header Image

popup message กับ scriptmanager ajax

ใช้บ่อยเหลือเกินแต่ลืมทุกทีเลย จนได้พี่ยุทธมาช่วยไว้ ที่จริงการเรียก js ใน .net มีหลายวิธีไม่ว่าจะเป็น Response.Write(js) หรือจะใช้ registerStartupScript(type,id, js, true) แล้วก็ยังมีวิธีอื่นๆอีก เอาไว้คราวหน้าจะเอามาเสนอก็แล้วกันนะ แต่เมื่อพวกนี้มาเจอกับ scriptmanager ของ ajax แล้วก็เจอปัญหาขึ้นมาซะงั้น js มักจะไม่ทำงาน หว่าอย่างนี้ก็แย่เลยซินะ อิอิ แต่ไม่ต้องห่วงมีวิธีมาช่วยเราแล้ว ตามนี้เลยนะ อ่ะอันนี้ขอให้เครดิตพี่ยุทธที่ใจดีให้คำตอบนะก๊าบ ขอบคุณกั๊บ

string   js  =  “”;

js = “alert(’ข้อความ’);”;

if(ScriptManager.GetCurrent(base.Page).IsInAsyncPostBack)

{

ScriptManager.RegisterStartupScript(this, this.GetType(),”Rating_Scritp_”+this.ClientId.ToString(),js,true);

}else{

this.Page.ClientScript.RegisterStartupScript(this.GetType(),this.ClientId,js,true);

}

Leave a Reply