I want to add a user control to my pages without page post backs.
I can't use Update Panels because I have file uploads control in the user controls.
I also don't want to put the custom controls in a page and then load it inside a page using jQuery load functions. Similarly I cannot use iframes.
How can I do it through some jQuery or AJAX?
This answer is posted by some user but he/she has removed the answer:
So i am posting his answer
Though i want to add a server controls in my application but i left with no choice except to use HTML Elements
StringBuilder b = new StringBuilder();
HtmlTextWriter h = new HtmlTextWriter(new StringWriter(b));
UserControl u = new Page().LoadControl("~/UserControl.ascx") as UserControl;
u.RenderControl(h);
return b.ToString();
This works only if all the controls in a USER CONTROL is of html type
Related
i have some LIST controls in my master page to that list i want to add attributes such as href attribute from code behind of master page based on some criteria if he is admin or user etc.
i have tried
Control mycontrol=FindControl(v.Item1) ///v.Item1 im getting from database which is actual id of control in my aspx code
mycontrol.Attributes.Add("href","~/sales.aspx")/// this is not working
please help im new to asp.net
Just use HTMLAnchor or HTML Control
//Example 1
HtmlAnchor ct = (HtmlAnchor)FindControl("CRM1");
ct.Attributes.Add("href", "~/Test.aspx");
//Example 2
HtmlControl ct2 = (HtmlControl)Page.Master.FindControl("CRM2");
ct2.Attributes.Add("href", "~/Test.aspx");
Just tested. Both worked for me in my Master page
I want to add dynamically button in html table.
I created a master page and another subpage.
On the sub page, I want to dynamically add a button in html table.
This is my code:
Button btnSend = new Button();
btnSend.ID = "btnSend";
btnSend.Text = "Send";
btnSend.Click += new System.EventHandler(btnSend_Click);
this.form1.Controls.Add(btnSend);
But I get an error:
form1 is not accessible from sub page.
Please help me to dynamically add a button into the html table.
If you use asp.net then you have no forms. So simply insert a button from the toolbox and set buttonName.visible = true or false as you need.
If you want to add dynamic controls to your sub page, then i suggest you to add a panel, and then simply use panel.controls.add(your button) and thats all.
Do you create the HTML table on codebehind? If so, you may add the button there.
If not, you may try putting a Literal there, and fill it with the code for an HTML button if needed.
In the early days of .NET, you had no choice. Your entire page content was wrapped in a single form tag and you made it work. Somewhere along the way, we started moving away from that, however where I read it eludes me. I recall reading that the new standard is not to put a single form tag in your master page and instead place the form tag in each usercontrol that needed it.
This worked well for me up until recently. I've now created a usercontrol that works fine if the form tag is in the Master page, but if the form control is in the usercontrol, when the form postsback, none of the controls retain their preselected values (i.e. my dropdownlist selection).
Should I go back to placing my form control in the Master page and strip the form tag out of all of my usercontrols? Or did I read correctly and the new recommendation is to put form tags in usercontrols?
If you are using ASP.NET web forms you should have the form tag in the master page.
See this link:
http://msdn.microsoft.com/en-us/library/fb3w5b53%28v=vs.100%29.aspx
From this article:
The user control does not have html, body, or form elements in it. These elements must be in the hosting page.
I want to open a regular .aspx page in a rad window.But the regular page consists of Site Map.I don't want that sitemap to be displayed when it is opened in rad window.
Please suggest me some solution.
I already tried this:
this.MasterpageFile="..//test.Master";
But in my page it does not work
So you will have ContentPlaceHolders which will automatically inherit from the master page. If you go to the regular .aspx page and head into Design view you will see sections with all the content from the Master Page.
If you click the little right arrow to the right of the area that looks like a Div, you should be able to change the content back to what you have in your regular aspx page.
Make a public property on MasterPage to show hide your site map , on your rad window page access that Property and make it hide.
public bool MyProperty()
{
// get and set your controls visibility
}
Access your property like this.Master.MyProperty = false
I wanted to load a .aspx page into contentplaceholder without making a postback. What I have is a master page with 3 contentplaceholders
1.headerContent
2.leftContent
3.mainContent
I have 3 links in the headercontent and according to the selection of those 3 links, i'm showing few menu's on the leftcontent. On selecting any of the loaded menu on the left content i wanted to show/load a .aspx page inside the "maincontent" through the codebehind(C#), without making a refresh or postback. The .aspx pages which i wanted to load aren't inheriting the masterpage.
Other than using Iframes, is there any way to accomplish this??
What I can suggest is to use user controls (.ascx) instead of pages. Have one page that loads all the controls from the start, this page will use the master page and will have its content place holder as the mainContent.
You can have each control inside a div on the page, and set the display of the div to none. Then you can use java script to display just the relevant user control.