Monday, March 26, 2012

dynamic <asp:TextBox> markup not editable

Hi,

I tried to write on the fly <asp:TextBox> markup using c#. Those markup are included in <div> markup.

The problem is that my textboxes are ReadOnly and I did nothing for that !!!
Whorse, when I paste the generated code into a new aspx page, it works, has anyone an idea ?

Here's my code :

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>KING : Saisie des frais</title>
<link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=StyleSheet.css"/>
</head>
<body>
<form id="formulaire" runat="server">
<atlas:ScriptManager ID="ScriptManager" runat="server" />
<div id="conteneur">
<div class="fdcaldate">
<%
string cal;
cal = "";
for (int i = 1; i < 31; i++){
cal += ("<div class=\"jo\"> L"+ i + " </div>") ;
}
Response.Write(cal);
%>
</div>
<div class="fdcalsaisie">
<%
string cal2;
cal2 = "";
for (int j = 1; j < 31; j++){
cal2 += ("<div class=\"jo\"><asp:TextBox ID=\"TextBox"+j+"\" runat=\"server\" BackColor=\"Transparent\" BorderColor=\"Transparent\" BorderStyle=\"None\" Height=\"20px\" Width=\"24px\">ici</asp:TextBox></div>\n") ;
}
Response.Write(cal2);
%>
</div>
</div>
</form
<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
</components>
</page>
</script>
</body>
</html

"text/xml-script">//schemas.microsoft.com/xml-script/2005">

hello.

this is not really an atlas question, but...

well, this won't work because you're adding the <asp:textbox> string to the output. you can't create an asp.net controlo like this with c#. to create a textbox, you have to:

TextBox txt = new TextBox();
txt.Text = ":...";

then you tipically have a placeholder on the page and you add the control to that placeholder's control collection.

No comments:

Post a Comment