Here you are trying to append some text in body of html. alert will not fire. Frist of all let me ask you, why can't you add a dynamic panel and call the alert method inside the script manager.
Raj
According to my calculations the problem doesn't exist.
khushboo_Nay...
Member
150 Points
210 Posts
create dynamic div dynamically and display alert message in div using script ScriptManager.Regist...
May 07, 2012 08:25 AM|LINK
Hello,
i have created dynamic div and display alert message in div tag using scriptmanager.registerclientscriptblock.but alert is not fired.
please see the below code.if any have any idea then please inform me as earlier as possible.
Thanks In Advance.
code
======
StringBuilder Script = new StringBuilder();
Script.AppendLine("<script type=text/javascript>");
Script.AppendLine("function JavaScriptFunction() {");
Script.AppendLine("var value = " + objEvaluatedWork.Message.ToString()+";");
Script.AppendLine("var divTag = document.createElement('div');");
Script.AppendLine("divTag.id = 'div2';");
Script.AppendLine("divTag.setAttribute('align', 'center');");
Script.AppendLine("divTag.style.margin = '0px auto';");
Script.AppendLine("divTag.innerHTML = '"+objEvaluatedWork.Message.ToString() +"';");
Script.AppendLine("alert('"+objEvaluatedWork.Message.ToString()+"');");
Script.AppendLine("}");
Script.AppendLine("</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Stop" + i, Script.ToString(), true);
Regards,
Khushboo Nayak.
friendster
Member
749 Points
189 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 09:42 AM|LINK
Hi,
Here you are trying to append some text in body of html. alert will not fire. Frist of all let me ask you, why can't you add a dynamic panel and call the alert method inside the script manager.
Raj
sriramabi
Contributor
4351 Points
1277 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 10:03 AM|LINK
hai
string script = "alert('Scores are updated successfully');window.location ='Default.aspx';";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);
thank u
shivalthakur
Participant
1839 Points
532 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 10:08 AM|LINK
Response.Write("Success");
Best Of Luck
Shival Thakur
DreamBig
Participant
1339 Points
622 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 10:34 AM|LINK
Try this:
function DynamicDiv(obj) { var dynDiv = document.createElement("div"); dynDiv.id = "div2"; dynDiv.innerHTML = obj; dynDiv.style.height = "20px"; dynDiv.style.width = "300px"; dynDiv.style.backgroundColor = 'gray'; document.body.appendChild(dynDiv); } </script> <asp:Button ID="btnClick" runat="server" Text="Call JS Function" OnClick="btnClick_Click" />Code-Behind
protected void btnClick_Click(object sender, EventArgs e) { string strMessage = "Ur custom message"; ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "DynamicDiv('" + strMessage + "');", true); }My Blog
khushboo_Nay...
Member
150 Points
210 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 10:44 AM|LINK
u r right but i want to create this dynamicdiv javascript in codebehind file.because i havent aspx page i have write code only baseclass.cs file.
khushboo_Nay...
Member
150 Points
210 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 10:45 AM|LINK
i have already used false instead of true but i got error that's why i used true.....
ramiramilu
All-Star
95503 Points
14106 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 11:23 AM|LINK
cant you use AJAX ModalPopup - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx
Thanks,
JumpStart
DreamBig
Participant
1339 Points
622 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 11:38 AM|LINK
i don't think you can display alert message in div tag, instead u can simply display an alert message using RegisterClientScriptBlock.
Try this:
private void ShowPopUpMsg(string msg) { StringBuilder sb = new StringBuilder(); sb.Append("alert('"); sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'")); sb.Append("');"); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true); }
My Blog
khushboo_Nay...
Member
150 Points
210 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 07, 2012 12:14 PM|LINK
but i want to set color,width,height in alert message that's why i have used div.