Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
an example of my xml file
<xmlScript xmlns.xsi="http//www.w3.org">
<greeting >
< data > hi how you doing today < /data >
</greeting >

<confirm >
< data > is this Mr Jones < /data >
</confirm >

</xmlScript>
// and so on



the following code saves the xmlscripts into myscript

string scriptpath = Server.MapPath("/xmlScript/" + ddlxmlScriptList.SelectedValue.ToString()); // drop down list (ddl) displaying the xml scripts
xmlScript myscript = new xmlScript(scriptpath);
myscript = myscript.LoadFile();
if (myscript.greeting != null)
{


How do i populate *myscript greeting* in a textbox??
}
Posted
Comments
Andy Lanng 30-Mar-15 8:35am    
Do you have the page constructed and have you included a text-box?
When do you need to populate the text-box? If it's when the page loads then that's easy enough. Even if it's on a post-back event (such as ddlxmlScriptList.SelectedValueChanged) then that's easy too. Otherwise please give more details

Thanks ^_^
Member 10353114 30-Mar-15 8:48am    
i have a page with a dropdown list (ddlxmlScriptList) that displays the xml scripts, when i click on one of them then it should populate in the textbox. Need more info?
Thanks for helping
Andy Lanng 30-Mar-15 8:51am    
Nope - I gotcha ;)
Member 10353114 31-Mar-15 1:17am    
hi, thanks for that. im busy implementing your code. just want to know what you meant by string SomeXmlLoadingStuff(ddlxmlScriptList.SelectedValue); the "someXmlLoadingStuff"
Andy Lanng 31-Mar-15 4:35am    
That was the code you included to save your xml and get the value of myscript.greeting. Think of it as shorthand for:
string scriptpath = Server.MapPath("/xmlScript/" + ddlxmlScriptList.SelectedValue.ToString()); // drop down list (ddl) displaying the xml scripts
xmlScript myscript = new xmlScript(scriptpath);
myscript = myscript.LoadFile();

1 solution

Ok - in the code-behind you need to override the onInit method:
C#
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    ddlxmlScriptList.SelectedValueChanged += XmlScriptListSelectedValueChanged;
}

Then, when the dropdown value is changed, the method 'XmlScriptListSelectedValueChanged(object sender, EventArgs e)' will run.

I know I am probably talking a bit below your level. Forgive me but I like fully complete answers and you did ask a very generic question :)

I know you know this because this is probably when your code to fetch the xml lives.

If that is not the case then perhaps you have a button. The same principle applies. As long as you have the page still in a loading state (such as when an event is running in the code behind, i.e. XmlScriptListSelectedValueChanged(sender,e)) then this is where and when you need to populate the text-box.

Populating the text-box is simply a case of assigning a string to the textbox's Text property:
C#
XmlScriptListSelectedValueChanged(object sender, EventArgs e){
    
    string theValueINeedInTheTextbox = SomeXmlLoadingStuff(ddlxmlScriptList.SelectedValue);
    tbxTheTextbox.Text = theValueINeedInTheTextbox; 
}


Please let me know if I have answered your question ^_^
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900