Binding text boxes and string dynamically in asp.net using placeholder -
i have following code in im using place holder hold dynamically created text boxes. pre init , loadviewstate overridden facilitate changes, method nextid incriment id 1 , render back. create method create new instance of textbox , add list.
my question can replace "#" in string str textbox , rest of string should appended , on final ui user should see textboxes instead of "#" , other string values is. im sorry if question seems irrelevant, im newbie......any appreciated, thanks
public partial class _default : system.web.ui.page { public void create() { textbox txt = new textbox(); txt.id = "txtfillup" + nextid.tostring(); dynamiccontrol.controls.add(txt); //dynamiccontrol.controls.add(new literalcontrol("<br>")); controllist.add(txt.id); } public list<string> controllist { { if (viewstate["controls"] == null) { viewstate["controls"] = new list<string>(); } return (list<string>)viewstate["controls"]; } } public string str = "# capital of #"; stringbuilder sb = new stringbuilder(); public int nextid { { return controllist.count + 1; } } protected override void onpreinit(eventargs e) { base.onpreinit(e); } protected override void loadviewstate(object savedstate) { base.loadviewstate(savedstate); foreach (string s in controllist) { textbox txt = new textbox(); txt.id = s; dynamiccontrol.controls.add(txt); //dynamiccontrol.controls.add(new literalcontrol("<br>")); } } protected void page_load(object sender, eventargs e) { foreach (char s in str) { if(s == '#') { create();//replace "#" textbox in string str. } else { //if chaacterr not "#" should appended is. } } dynamiccontrol.controls.add(//adding modified string displayed in ui); }
Comments
Post a Comment