Hi,
I currently have a form page containing dynamic controls. The form consists of both Dropdownlists as well as textboxes. When creating the form dynamically the IDs that I have assigned to each of the controls is A1, A2...
I need to retrieve the selectedvalue of the dropdown list and the text in text textboxes to save the data off to the database.
I am unable to access the control in my code behind page.
Could someone please tell me if we have something equivalent to the javascript getElementByID in C sharp?
Thanks
Aditi
Loading
Aditi IyerPosted Oct 6, 2010, 5:23 AM
I have managed to access the dynamic controls in the code behind.
Thanks for all your suggestions.
Sam HobbsPosted Oct 6, 2010, 5:20 AM
http://social.msdn.microsoft.com/Search/en-US?query=getElementByID&ac=3
I really think your question is answered there. If after you have read the documentation, you have specific questions, then you will get better help here. But you must read the documentation; if you don't read the documentaton, don't complain if you don't get much help.
If you read the documentation, you will see that getElementByID is not part of JavaScript. It will help you very much to understand what it actually is a part of.
One thing I will mention that can be confusing is that there are some classes in the System.Windows.Forms namespace that are relevant to what you are doing. There are other classes in COM classes that are similar. The classes in the System.Windows.Forms namespace are easier to use in .Net but the COM classes are much more complete. I apologize if that is confusing but I don't have time to explain all of it.
theLizardPosted Oct 6, 2010, 4:18 AM
You need to research call backs and register client scripts.
I do not have time to find and get you examples so researching these options is the way for you to move forward.
Mike GoldPosted Oct 5, 2010, 5:05 PM
Aditi IyerPosted Oct 5, 2010, 10:24 AM
I am not trying to do it in Javascript. I am trying to access the control within C sharp itself.
code to create the HTML :
if (drOptions.HasRows)
{
if (drQuestions.GetValue(4).ToString() == "Select")
{
td_Answer.HorizontalAlign = HorizontalAlign.Right;
DropDownList ddl = new DropDownList();
ddl.ID = "A" + drQuestions.GetValue(0).ToString();
while (drOptions.Read())
{
ddl.Items.Add(new ListItem(drOptions.GetValue(2).ToString(),drOptions.GetValue(0).ToString()));
}
tr_Question.Controls.Add(td_Answer);
td_Answer.Controls.Add(ddl);
}
}
drOptions.Close();
Code to access the values :
SqlCommand cmdQ = new SqlCommand();
cmdQ.Connection = dbConnQ1;
cmdQ.Connection.Open();
cmdQ.CommandText = "Select * from DSE_Questions ORDER BY Q_Order";
SqlCommand cmdSQL = new SqlCommand();
cmdSQL.Connection = dbConnAnswers;
cmdSQL.Connection.Open();
drQuestions = cmdQ.ExecuteReader();
if (drQuestions.HasRows)
{
while (drQuestions.Read())
{
Control ctl;
/*cmdSQL.CommandText = "p_InsertDSEAnswers '" & Trim(System.Web.HttpContext.Current.User.Identity.Name.Substring(9, 7).ToUpper()) & "','" & drQuestions.GetValue(0).ToString() & "'," & );
cmdSQL.ExecuteNonQuery();
*/
}
}
vijayPosted Oct 5, 2010, 10:21 AM
please tray to this code