Reputation: 11
i have one master page and one content page. In my master page i have one textbox,one button and one content placeholder. the aim is to change the text(not assigning into any fields just text/content of content page) in the content page with the text entered by the user in the textbox which is in the master page. here is the problem
even though i changed the text in the textbox and button clicked the previous text is updated and no change in the content page... here is my code in master page
public partial class example : System.Web.UI.MasterPage
{
FileInfo fil = new FileInfo("c:/documents and settings/administrator/my documents/visual studio 2010/Projects/WebApplication1/WebApplication1/contentpage.aspx");
protected void Page_Load(object sender, EventArgs e)
{
contenttext.Text = File.ReadAllText(fil.ToString());
}
protected void clicked_Click(object sender, EventArgs e)
{
File.WriteAllText(fil.ToString(),this.contenttext.Text);
Response.Redirect("contentpage.aspx");
}
}
Upvotes: 1
Views: 1594
Reputation: 1
//.aspx page
and this is .cs page protected void Page_Load(object sender, EventArgs e) { for (int i = 1; i <= 5; i++) { TextBox tb = new TextBox(); tb.ID = "textbox" + i.ToString(); tb.Attributes.Add("runat", "server"); MyPanel.Controls.Add(tb); } }
protected void btnReadTextBoxValue_Click(object sender, EventArgs e)
{
for (int i = 1; i <=5; i++)
{
//Append the master page content place holder id with textbox then it find value and work
string str ="ctl00$ContentPlaceHolder3$"+"textbox" + i.ToString();
TextBox retrievedTextBox = FindControl(str) as TextBox;
if (retrievedTextBox != null)
{
lblResult.Text = ((TextBox)retrievedTextBox).Text;
break;
}
else
{
lblResult.Text = "No text box has been created!";
}
}
Upvotes: 0
Reputation: 61
// Gets a reference to a TextBox control that not in
// a ContentPlaceHolder
Textbox txt = (Textbox) Master.FindControl("masterPageLabel");
if(txt != null)
{
Textbox1.Text = Textbox2.Text;
}
try this and put it on click of button in code behinde
Upvotes: 1