create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlockhttp://forums.asp.net/t/1800880.aspx/1?create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockWed, 09 May 2012 09:49:08 -040018008804968602http://forums.asp.net/p/1800880/4968602.aspx/1?create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockcreate dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>Hello,</p> <p>i have created dynamic div and display alert message in div tag using scriptmanager.registerclientscriptblock.but alert is not fired.</p> <p>please see the below code.if any have any idea then please inform me as earlier as possible.</p> <p>Thanks In Advance.</p> <p></p> <p>code</p> <p>======</p> <p>StringBuilder Script = new StringBuilder();<br> Script.AppendLine(&quot;&lt;script type=text/javascript&gt;&quot;);</p> <p>Script.AppendLine(&quot;function JavaScriptFunction() {&quot;);<br> Script.AppendLine(&quot;var value = &quot; &#43; objEvaluatedWork.Message.ToString()&#43;&quot;;&quot;);<br> Script.AppendLine(&quot;var divTag = document.createElement('div');&quot;);<br> Script.AppendLine(&quot;divTag.id = 'div2';&quot;);<br> Script.AppendLine(&quot;divTag.setAttribute('align', 'center');&quot;);<br> Script.AppendLine(&quot;divTag.style.margin = '0px auto';&quot;);<br> Script.AppendLine(&quot;divTag.innerHTML = '&quot;&#43;objEvaluatedWork.Message.ToString() &#43;&quot;';&quot;);<br> Script.AppendLine(&quot;alert('&quot;&#43;objEvaluatedWork.Message.ToString()&#43;&quot;');&quot;);<br> <br> Script.AppendLine(&quot;}&quot;);</p> <p>Script.AppendLine(&quot;&lt;/script&gt;&quot;);</p> <p>ScriptManager.RegisterClientScriptBlock(this, this.GetType(), &quot;Stop&quot; &#43; i, Script.ToString(), true);</p> <p></p> <p>Regards,</p> <p>Khushboo Nayak.</p> 2012-05-07T08:25:23-04:004968754http://forums.asp.net/p/1800880/4968754.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>Hi,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Here you are trying to append some text in body of html. alert will not fire. Frist&nbsp; of all let me ask you, why can't you add a dynamic panel and call the alert method inside the script manager.</p> <p></p> <p>Raj</p> 2012-05-07T09:42:20-04:004968805http://forums.asp.net/p/1800880/4968805.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>hai</p> <p>&nbsp; string script = &quot;alert('Scores are updated successfully');window.location ='Default.aspx';&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ClientScript.RegisterClientScriptBlock(this.GetType(), &quot;Alert&quot;, script, true);</p> <p>thank u</p> 2012-05-07T10:03:58-04:004968810http://forums.asp.net/p/1800880/4968810.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p></p> <blockquote><span class="icon-blockquote"></span> <h4>khushboo_Nayak</h4> <p></p> <p>Hello,</p> <p>i have created dynamic div and display alert message in div tag using scriptmanager.registerclientscriptblock.but alert is not fired.</p> <p>please see the below code.if any have any idea then please inform me as earlier as possible.</p> <p>Thanks In Advance.</p> <p></p> <p>code</p> <p>======</p> <p>StringBuilder Script = new StringBuilder();<br> Script.AppendLine(&quot;&lt;script type=text/javascript&gt;&quot;);</p> <p>Script.AppendLine(&quot;function JavaScriptFunction() {&quot;);<br> Script.AppendLine(&quot;var value = &quot; &#43; objEvaluatedWork.Message.ToString()&#43;&quot;;&quot;);<br> Script.AppendLine(&quot;var divTag = document.createElement('div');&quot;);<br> Script.AppendLine(&quot;divTag.id = 'div2';&quot;);<br> Script.AppendLine(&quot;divTag.setAttribute('align', 'center');&quot;);<br> Script.AppendLine(&quot;divTag.style.margin = '0px auto';&quot;);<br> Script.AppendLine(&quot;divTag.innerHTML = '&quot;&#43;objEvaluatedWork.Message.ToString() &#43;&quot;';&quot;);<br> Script.AppendLine(&quot;alert('&quot;&#43;objEvaluatedWork.Message.ToString()&#43;&quot;');&quot;);<br> <br> Script.AppendLine(&quot;}&quot;);</p> <p>Script.AppendLine(&quot;&lt;/script&gt;&quot;);</p> <p><span style="text-decoration:line-through">ScriptManager.RegisterClientScriptBlock(this, this.GetType(), &quot;Stop&quot; &#43; i, Script.ToString(), true);</span></p> <p><span style="text-decoration:line-through"><br> </span></p> <p><span style="text-decoration:line-through"><br> </span></p> <p><span style="text-decoration:line-through"><br> </span>you should use false insted of true.</p> <p><strong>ScriptManager.RegisterClientScriptBlock(this, this.GetType(), &quot;Stop&quot; &#43; i, Script.ToString(), false);</strong></p> <p></p> <p></p> <p>hope will help you</p> <p></p> </blockquote> 2012-05-07T10:08:06-04:004968858http://forums.asp.net/p/1800880/4968858.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p><span style="text-decoration:underline"><strong>Try this:</strong></span></p> <pre class="prettyprint">function DynamicDiv(obj) { var dynDiv = document.createElement(&quot;div&quot;); dynDiv.id = &quot;div2&quot;; dynDiv.innerHTML = obj; dynDiv.style.height = &quot;20px&quot;; dynDiv.style.width = &quot;300px&quot;; dynDiv.style.backgroundColor = 'gray'; document.body.appendChild(dynDiv); } &lt;/script&gt; &lt;asp:Button ID=&quot;btnClick&quot; runat=&quot;server&quot; Text=&quot;Call JS Function&quot; OnClick=&quot;btnClick_Click&quot; /&gt;</pre> <p><br /><br /><span style="text-decoration: underline;"><strong>Code-Behind</strong></span><br /><br /></p> <pre class="prettyprint">protected void btnClick_Click(object sender, EventArgs e) { string strMessage = "Ur custom message"; ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "DynamicDiv('" + strMessage + "');", true); }</pre> <p><br> <br> <br> </p> 2012-05-07T10:34:38-04:004968869http://forums.asp.net/p/1800880/4968869.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>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.</p> <p></p> 2012-05-07T10:44:39-04:004968871http://forums.asp.net/p/1800880/4968871.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>i have already used false instead of true but i got error that's why i used true.....</p> 2012-05-07T10:45:37-04:004968945http://forums.asp.net/p/1800880/4968945.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>cant you use AJAX ModalPopup -&nbsp;<a href="http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx">http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx</a>&nbsp;</p> <p>Thanks,</p> 2012-05-07T11:23:23-04:004968982http://forums.asp.net/p/1800880/4968982.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>i don't think you can display alert message in div tag, instead u can simply display an alert message using RegisterClientScriptBlock.</p> <pre class="prettyprint">Or else, kindly tell what exactly is your requirement..</pre> <p><span style="text-decoration: underline;"><strong>Try this:</strong></span></p> <pre class="prettyprint">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); }<br /><br /></pre> 2012-05-07T11:38:05-04:004969043http://forums.asp.net/p/1800880/4969043.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>but i want to set color,width,height in alert message that's why i have used div.</p> 2012-05-07T12:14:20-04:004970141http://forums.asp.net/p/1800880/4970141.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>For dynamically creating div, try this:</p> <pre class="prettyprint">System.Web.UI.HtmlControls.HtmlGenericControl dynDiv = new System.Web.UI.HtmlControls.HtmlGenericControl(&quot;DIV&quot;); dynDiv.ID = &quot;dynDivCode&quot;; dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, &quot;Gray&quot;); dynDiv.Style.Add(HtmlTextWriterStyle.Height, &quot;20px&quot;); dynDiv.Style.Add(HtmlTextWriterStyle.Width, &quot;300px&quot;); dynDiv.InnerHtml = &quot;I was created using Code Behind&quot;; this.Controls.Add(dynDiv);</pre> <p>And to show a alert using RegisterCLientScriptBlock, try this:</p> <pre class="prettyprint">ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Alert", "alert('Alert Message');", true);</pre> <p><br> <br> </p> 2012-05-08T06:05:49-04:004972494http://forums.asp.net/p/1800880/4972494.aspx/1?Re+create+dynamic+div+dynamically+and+display+alert+message+in+div+using+script+ScriptManager+RegisterClientScriptBlockRe: create dynamic div dynamically and display alert message in div using script ScriptManager.RegisterClientScriptBlock <p>Hi khushboo_Nayak,</p> <p>In order to resolve your issue, you need to know use of&nbsp;ClientScriptManager<span>.</span>RegisterClientScriptBlock method at first. It registers the client script with the <span>Page</span> object using a type, key, script literal, and Boolean value indicating whether to add script tags. That means you need to call&nbsp;the javascript function&nbsp;in the code. Please see the link below which has a dem demonstrating the use of the <span>RegisterClientScriptBlock</span> method.</p> <p><a href="http://msdn.microsoft.com/en-us/library/bahh2fef.aspx">http://msdn.microsoft.com/en-us/library/bahh2fef.aspx</a></p> <p>Thus, if you want to call the function JavaScriptFunction, you need to invoke it in the .aspx as follows:</p> <pre class="prettyprint">&lt;input type=&quot;button&quot; value=&quot;ClickMe&quot; onclick=&quot;JavaScriptFunction()&quot; /&gt;</pre> <p>And&nbsp;modify your code as follows:</p> <pre class="prettyprint">ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Stop" + i, Script.ToString(), true);</pre> <p>In addition, I am not sure why you want to display the alert message in div. In my opinion,&nbsp;you can use&nbsp;AJAX ModalPopup to display content to the user. It is very easy to use. For details, please check the link below:</p> <p><a href="http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx">http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx</a></p> <p>Best wishes,</p> 2012-05-09T09:49:08-04:00