System.Web.UI.HtmlControls.HtmlGenericControl dynDiv =
new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
dynDiv.ID = "dynDivCode";
dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Gray");
dynDiv.Style.Add(HtmlTextWriterStyle.Height, "20px");
dynDiv.Style.Add(HtmlTextWriterStyle.Width, "300px");
dynDiv.InnerHtml = "I was created using Code Behind";
this.Controls.Add(dynDiv);
And to show a alert using RegisterCLientScriptBlock, try this:
In order to resolve your issue, you need to know use of ClientScriptManager.RegisterClientScriptBlock method at first. It registers the client script with the
Page object using a type, key, script literal, and Boolean value indicating whether to add script tags. That means you need to call the javascript function in the code. Please see the link below which has a dem demonstrating the use of the
RegisterClientScriptBlock method.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Stop" + i, Script.ToString(), true);
In addition, I am not sure why you want to display the alert message in div. In my opinion, you can use AJAX ModalPopup to display content to the user. It is very easy to use. For details, please check the link below:
DreamBig
Participant
1339 Points
622 Posts
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 08, 2012 06:05 AM|LINK
For dynamically creating div, try this:
System.Web.UI.HtmlControls.HtmlGenericControl dynDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); dynDiv.ID = "dynDivCode"; dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Gray"); dynDiv.Style.Add(HtmlTextWriterStyle.Height, "20px"); dynDiv.Style.Add(HtmlTextWriterStyle.Width, "300px"); dynDiv.InnerHtml = "I was created using Code Behind"; this.Controls.Add(dynDiv);And to show a alert using RegisterCLientScriptBlock, try this:
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Alert", "alert('Alert Message');", true);My Blog
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: create dynamic div dynamically and display alert message in div using script ScriptManager.Re...
May 09, 2012 09:49 AM|LINK
Hi khushboo_Nayak,
In order to resolve your issue, you need to know use of ClientScriptManager.RegisterClientScriptBlock method at first. It registers the client script with the Page object using a type, key, script literal, and Boolean value indicating whether to add script tags. That means you need to call the javascript function in the code. Please see the link below which has a dem demonstrating the use of the RegisterClientScriptBlock method.
http://msdn.microsoft.com/en-us/library/bahh2fef.aspx
Thus, if you want to call the function JavaScriptFunction, you need to invoke it in the .aspx as follows:
And modify your code as follows:
In addition, I am not sure why you want to display the alert message in div. In my opinion, you can use AJAX ModalPopup to display content to the user. It is very easy to use. For details, please check the link below:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ModalPopup/ModalPopup.aspx
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store