Question

I think it is a very simple question, but I'm just stuck on it.

I'm developing custom page for my SharePoint 2010 portal, and I need to add a button (or other elements) to my .aspx page:

<input type="button" id="btnID" onclick="window.location.href='/CustomPage.aspx'" value="GO!" />

I've tried to do it from codebehind:

System.Web.UI.WebControls.Button button = new System.Web.UI.WebControls.Button();
button.OnClientClick = "window.location.href='/CustomPage.aspx'";
button.ID = "btnID";
button.Text = "GO!";
IVersionedContent9.Controls.Add(button);

However, I get this on the page:

<input type="submit" name="ctl00$PlaceHolderMain$UIVersionedContent9$btnID" value="GO!" onclick="window.location.href='/CustomPage.aspx';WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$PlaceHolderMain$UIVersionedContent9$btnID&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_PlaceHolderMain_UIVersionedContent9_btnID" />

I'm not sure with the class, but maybe something else is wrong...

How can I add simple HTML (not ASP.NET) button to the page, without any additional values?

Thanks in advance!

Was it helpful?

Solution

you can do Response.Write, or you can use asp:Literal.

var ltlCnt = new LiteralControl();
string divStart = @"<div>";
ltlCnt.Text += divStart;
string divEnd = @"</div>";
ltlCnt.Text += divEnd;

this.[divOnPage].Controls.Add(ltlCnt);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top