How can Access a Div without add runar="server" in code behind?
-
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
if (div != null)
{
div.InnerHtml = "test message";
}
}i used this code, but not working? is there any solution? i search google but cant get relevant answer. please help me.
-
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
if (div != null)
{
div.InnerHtml = "test message";
}
}i used this code, but not working? is there any solution? i search google but cant get relevant answer. please help me.
The obvious question is why not add the runat attribute?
I know the language. I've read a book. - _Madmatt
-
The obvious question is why not add the runat attribute?
I know the language. I've read a book. - _Madmatt
-
if i did add runat="server" i can access mydiv.innerText from .cs page. please let me know if any way to access that.
When you add a runat=server attribute to an html element it is automatically wrapped as a HtmlGenericControl. Your first attempt gained you nothing. So rather than this
HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
if (div != null)
{
div.InnerHtml = "test message";
}You could have this
div.InnerText = "test message";
I know the language. I've read a book. - _Madmatt
-
When you add a runat=server attribute to an html element it is automatically wrapped as a HtmlGenericControl. Your first attempt gained you nothing. So rather than this
HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
if (div != null)
{
div.InnerHtml = "test message";
}You could have this
div.InnerText = "test message";
I know the language. I've read a book. - _Madmatt
-
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl div = (HtmlGenericControl)Page.FindControl("mydiv");
if (div != null)
{
div.InnerHtml = "test message";
}
}i used this code, but not working? is there any solution? i search google but cant get relevant answer. please help me.