cesark
Mar 24th, 2004, 03:40 AM
I want to generate dynamically web form controls from my aspx VB.NET page without doing Postbacks. Which is the best way of doing this? Because if I generate the form controls from a JavaScript function these form controls are Html form controls, so it doesn’ t have the same functionality and advantages than ASP.NET form controls have. For instance I can’t do server validations, the state of the entered form data doesn’ t persist after Postbacks, I can’t reference them from an ASP.NET subroutines and do operations with them, etc…
Now I know how to generate the form controls without doing Postbacks, see the example below. (You can copy and paste this code and see the performance in the Web)
The performance: When you choose the option 7 from the dropdownlist, the web form control (in this case an input text) appears.
<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1"%>
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form id="formUser" runat="server">
<table width="835" height="30">
<tr>
<td width="119">Select the Activity:</td>
<td width="281"><asp:dropdownlist id="activity" runat="server" onChange="checkAct();">
<asp:listitem Value="0" Text="(Select the Activity)"></asp:listitem>
<asp:listitem Value="1" Text="Activity 1"></asp:listitem>
<asp:listitem Value="2" Text="Activity 2"></asp:listitem>
<asp:listitem Value="3" Text="Activity 3"></asp:listitem>
<asp:listitem Value="4" Text="Activity 4"></asp:listitem>
<asp:listitem Value="5" Text="Activity 5"></asp:listitem>
<asp:listitem Value="6" Text="Activity 6"></asp:listitem>
<asp:listitem Value="7" Text="Activity 7"></asp:listitem>
</asp:dropdownlist></td>
<td width="155" id="title"></td>
<td width="260" id="inputField"></td>
</tr>
</table>
</form>
</body>
</html>
<script language="JavaScript">
function checkAct() {
var Activity = document.forms[0].activity.value
var myTD1 = document.getElementById("title");
var myTD2 = document.getElementById("inputField");
if (Activity == "7") {
myTD1.innerHTML = "Type the other Activity:";
myTD2.innerHTML = "<Input type='text' id='act'>";
} else {
myTD1.innerHTML = "";
myTD2.innerHTML = "";
}
}
checkAct();
</script>
How can I generate dynamically web form controls without doing Postbacks, and at the same time to be able to take advantage of all the functionality of the ASP.NET form controls?
Thank you,
Cesar
Now I know how to generate the form controls without doing Postbacks, see the example below. (You can copy and paste this code and see the performance in the Web)
The performance: When you choose the option 7 from the dropdownlist, the web form control (in this case an input text) appears.
<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1"%>
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form id="formUser" runat="server">
<table width="835" height="30">
<tr>
<td width="119">Select the Activity:</td>
<td width="281"><asp:dropdownlist id="activity" runat="server" onChange="checkAct();">
<asp:listitem Value="0" Text="(Select the Activity)"></asp:listitem>
<asp:listitem Value="1" Text="Activity 1"></asp:listitem>
<asp:listitem Value="2" Text="Activity 2"></asp:listitem>
<asp:listitem Value="3" Text="Activity 3"></asp:listitem>
<asp:listitem Value="4" Text="Activity 4"></asp:listitem>
<asp:listitem Value="5" Text="Activity 5"></asp:listitem>
<asp:listitem Value="6" Text="Activity 6"></asp:listitem>
<asp:listitem Value="7" Text="Activity 7"></asp:listitem>
</asp:dropdownlist></td>
<td width="155" id="title"></td>
<td width="260" id="inputField"></td>
</tr>
</table>
</form>
</body>
</html>
<script language="JavaScript">
function checkAct() {
var Activity = document.forms[0].activity.value
var myTD1 = document.getElementById("title");
var myTD2 = document.getElementById("inputField");
if (Activity == "7") {
myTD1.innerHTML = "Type the other Activity:";
myTD2.innerHTML = "<Input type='text' id='act'>";
} else {
myTD1.innerHTML = "";
myTD2.innerHTML = "";
}
}
checkAct();
</script>
How can I generate dynamically web form controls without doing Postbacks, and at the same time to be able to take advantage of all the functionality of the ASP.NET form controls?
Thank you,
Cesar