Dynamically Loading Controls And Postbacks?
Mar 18, 2011
On a dashboard page I'm loading several controls dynamically; the controls always need to be loaded so there is no if (!Page.IsPostBack) code. The problem though is in that in the code-behind, we are using Request.Form.GetValues and a particular dropdown field's value is always null (presumably because the controls are being cleared and reloaded on a postback) and this is triggering an error later on in the page that expectes a value from this dropdown. I have to use Request.Form.GetValues because the page enables dynamically adding rows (each row containing 5+ HTML inputs) via Javascript.
If I check for postback, then the button event of the control does not fire at all but instead the dashboard page is reloaded, and no controls are loaded at all (i.e. the page is blank).
How do I get around this issue? I need to dynamically load the controls at all times, but I also need to retrieve the values via Request.Form.GetValues.
EDIT
Here's what the code looks like, roughly:
(Client-side HTML)
<table>
<tr>
<td align="center">
<select id="Class1" class="txtboxcomm" name="Class1" runat="server" />
<a href="javascript:classFinder('1')"> Look Up</a>
</td>
</tr>
</table>
<div id="action">
<asp:LinkButton ID="ibtnGetQuote" runat="server" OnClick="ibtnGetQuote_Click" CssClass="getQuote" AccessKey="G">Get Quote</asp:LinkButton>
</div>
(Server-side, in ibtnGetQuote_Click - this is actually a loop since user can append multiple rows; "i" is appended to the word "Class" to find the exact row)
IList<string> classes = this.GetFormValues("Class1");
// This will return null all the time...
private IList<string> GetFormValues(string clientID)
{
String[] values;
values = Request.Form.GetValues(clientID);
if (values == null)
{
Control ctl = FindControl(clientID); // uses built-in FindControl method
values = Request.Form.GetValues(ctl.ClientID);......
The original code was hardcoding the "ctl00$xx$xx" stuff, but the control may or may not be loaded so we cannot guarantee the name the control will get. In fact, I'm not even sure if this will work for all scenarios since only the FIRST control is a server control, the rest are just standard HTML controls so wouldn't have a "ClientID".
View 3 Replies
Similar Messages:
Sep 27, 2010
Can I dynamically create controls in Silverlight without a postback to the server (even an asynchronous one). Does silverlight drag-n-drop requires postback?
I'm asking this because I've an asp.net application where I dynamically create/delete lots of controls. So after the postback I'm getting error with view state stating that the control tree doesn't match the view state tree.
Can I avoid such problems in Silverlight?
View 4 Replies
May 6, 2010
I have a C# web application that dynamically adds user controls to the default page for whatever "mode" the application is in. The problem is that it is not persisting these across postbacks. How do I persist these across postbacks and keep the content of the controls that are in the user control?
For instance, say I have a user control that creates a new tour record. The user clicks on the Tour item from the menu on the default page, it dynamically loads the tours user control. The user then fills out the form in the tours user control and clicks save. This is where the problem happens. When the postback occurs, the web application has no idea that the new tours user control was ever loaded. So, no save takes place because the Save button's click event never even gets fired.
View 11 Replies
May 26, 2010
i am currently working on a webform that has several dynamically populated dropdown lists. this works just fine, however, i have other web controls that require to have a postback..and at the time the page postsback, it reloads my dropdownlists, reseting whatever option i had chosen...
what can i do to resolve this?
View 2 Replies
Sep 1, 2010
I am loading a series of controls in the Page_Load event. However, I have to recreate those controls each page load, which means storing their data elsewhere. This is cumbersome.
protected void Page_Load(object sender, EventArgs e)
{
MyControl control = (MyControl)LoadControl(...);
control.Initialize(GlobalClass.controlData);
//^gives the control the data it had previously.
//Or use ViewState["controlData"] if serializable.
Controls.Add(control);
}
I feel like I should be using if (!IsPostBack) {}, but I don't know how, or why. In contrast, if I place the controls into the markup, then the controls seem to stay persistent. For example, a button in mark-up will remember any changes to its Text property (I think?).
<asp:Button ID="buttonText" runat="server"
Text="Text Segment" onclick="buttonText_Click" />
How do I maintain some sort of persistence with dynamically added controls, like controls added via mark-up? This would save me much work and frustration.
(I've coded for a small eternity, but the more I do ASP.NET, the more confused I become. Which is exactly the opposite of what how I understood learning to work :-P.)
View 2 Replies
Nov 19, 2010
I have added some combobox and texboxes in gridview dynamically to provide the data entry like operations.i have fetched and reset the value of these dynamically added controls on button click as ->
[Code]....
[Code]....
View 2 Replies
Apr 16, 2010
I need some on techniques to perform page redirect in asp.net. Which one is more recommended to use in asp.net?
Dynamically changed the src of the Iframe to difference aspx.
[code]....
View 1 Replies
Dec 27, 2010
I am trying to create my own website management framework similar to DNN/SiteFinity (only a mucho cut down version).
One of the big (but common) features is to be able to dynamically add user controls to provide additional functionality.
I would prefer to use a pre-compiled .NET "Web Application" over a dynamically compiled "Website".
What are the implications of using LoadControl method to dynamically add a user control for a pre-compiled web applications with specific regard to:
Session (preume I am using the stateserver)What happens to all the other users - will they be logged out?
Application pool recycling due to changes to some compilation??
I am not sure I have ever dynamically added a user control to a pre-compiled web applications as I have mainly been using "Websites" so I am making a large presumption that it will work because if the website is pre-compiled, does this mean the dynamically added user control will be dynamically compiled as required even though the site is pre-compiled?
EDIT
I also forgot to mention that the user controls will be outside of the application directory and so won't be published during web deploy - they will be uploaded via another website.
View 2 Replies
Nov 15, 2010
The web page I am trying to (slowly) build should allow users to add whichever user controls they want on their page, and order them whichever way they like. This is saved in a database.
So each user could have a different number of controls on the page.
This is the design code, at the minute the user controls are fixed and are not loaded dynamically. They user controls are stored in 'blocks' which look like widgets on the page and can be dragged about to different columns. For each user the layout is stored in the DB i.e. which blocks are in column 1 and which blocks in column 2 etc.
How could I change this so that it can create a 'block' div for each user control returned from the database and put the user control in that block and in the right column?
[Code]....
View 15 Replies
Dec 16, 2010
I can't figure out how to get the legend to populate all the "strReason" and get the correct percents to show for each column. This is where I'm at right now.
[Code]....
View 1 Replies
Apr 17, 2010
I am using ASP.Net 2.0 with Ajax.
I am working on a pretty heavy page in an application and the scenario is:
There is a Tab control in the page, having four tabs. These tabs individually consist of different user controls and other asp controls. Most of these usercontrols in turn consist of other user controls. Every user control contains huge javaScript functions which validate them, populate controls and call web services.
What I am trying to achieve is to load only the Tab and its user controls on the page load and when the user clicks on a specific tab, load its contents (User controls) dynamically. Once that is done, I am setting the tab's postback to false to prevent loading it again once loaded.
I tried to achieve this by making the user controls in the other tabs - visible="false" in the markup and loading them from server side on some specific event. But that causes the javaScript functions in those user controls to give errors ('Object expected') when I go to that tab.
If I set the user controls in the other tabs to visible true, then no matter what; the page life cycle goes to each registered control and loads every subsequent control in that web user control which makes the main page slow (on loading and every postback).
The position of the Tab and the inner user controls is fixed. Although I am taking care that no data is populated unnecessarily on the page and user controls on hidden tabs, I dont want the tabs to get loaded altogether unless requested. If I load them on runtime, their corresponding javaScripts start giving errors.. note that I am not generating the controls on runtime, they exist in the page design. I just dont want to load them dynamically
View 4 Replies
Mar 2, 2010
First, I would like to apologize, the search on the site wasn't working, so I don't know if I'm missing an existing post or not.
I have a web page that uses a master page file. I am using a third party control from Component One(TabStrip), the tabs are rendered as links on the final page. When a tab(link) is clicked, I need to load the appropriate web user control associated with that tab. Each web user control has its own post backs and methods. I know that I can load the controls on the "SelectionChanged" event of the TabStrip control, but then any postback created by the web user control that is loaded causes the page to refresh and the control was never loaded in viewstate. So, I tried to put my procedure of loading the web user control into the page_init method. This would work, if I could read which link was clicked on from within the page_init method. I tried using a javascript function to run "onclick" of the tabs and within it setting the value of a hidden control. I have verified that the javascript works and that the hidden control's value is getting set correctly. When I get into the page_init method, the value of the hidden control is not readable.
I'm tying to understand the page lifecycle to the fullest, but I don't see what I'm missing here. I know that I need to load the web user controls in the page_init method in order to persist the page as a whole, but how can I get which tab(link) was clicked to know which control should be loaded?
View 5 Replies
May 7, 2015
Load data while Scrolling Page down with jQuery AJAX and ASP.Net.
I want to implement same thing but want to get data base on User input and implement the same. How to write Store Procedure where i can use where clause.
View 1 Replies
Jan 26, 2011
I have the following code in my <head>
<% if(Context.User.IsInRole("Reseller")) {%>
<link href="<%: themelocation %>" rel="stylesheet" type="text/css" />
<%} else {%>
<link href="<%= Url.Content("~/Content/custom-theme/jquery-ui-1.8.5.custom.css") %>" rel="stylesheet" type="text/css" />
<%} %>
The issue is with themelocation, which is declared just above this block of code - like so:
<%
var reseller = new Reseller();
var storeSettings = new StoreSettings();
var themelocation = "";
if (Context.User.Identity.IsAuthenticated)
{
var resellerRepository = new ResellerRepository();
reseller = resellerRepository.GetResellerByUsername(Context.User.Identity.Name);
var storeSettingsRepository = new StoreSettingsRepository();
storeSettings = storeSettingsRepository.GetStoreSettings((int) reseller.StoreSettingsID);
themelocation = storeSettings.Theme.StylesheetLocation;
}
%>
Setting a break point shows that themelocation holds the string I need, but when the page is run - it generates a 400 - Bad Request error, and the net tab in firebug reveals its looking for this:
http://localhost:50982/%3C%:%20themelocation%20%%3E
Where am I going wrong here? Why is it using the variable name, and not what it contains?
I'm using ASP.NET MVC2, and all of this code is located on my master page.
View 1 Replies
Mar 9, 2012
Right now I've got a large .aspx page - starts out loading tons of .css and .js files...
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AWCOffice.aspx.vb" Inherits="_AWCOffice" EnableViewState="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
[Code] ....
Then what follows is a large pile of javascript code - about 5800 lines of javascript code.
Code: <script type="text/javascript">
This is the main application. At the moment I like to keep it in the .aspx page because it's constantly changing and I don't want to worry about client caching and versioning.
After the JAVASCRIPT code comes the html - about 2000 lines of it.
Starts like this
Code:
</script>
</head>
<body>
<form id="form1" onsubmit="return false;" runat="server">
<div id="acs-system" class="acs-ddreflector acs-dddynamic">
<div id="acs-binder" class="noPrint">
[Code] ....
The DIV ACS-SYSTEM is the only visible area of this HTML.
The DIV ACS-POOL has a css style of display:none and holds template HTML that jQuery copies into the ACS-SYSTEM dom space as the app runs.
Here's the actual question.
Most of the 2000 lines of HTML in the ACS-POOL is customer specific - not all of my customers need all 2000 lines of this HTML. And as I add customers the nightmare of managing all this in one "SOURCE FILE" becomes daunting.
Never mind the wasted band width of giving all my customers all this HTML - even parts they do not need.
What kind of options do I have for breaking down and "dynamically" loading this in a more CUSTOMER-SPECIFIC fashion?
I think I could use jQuery to simply feed it from my "boot webservice" call - but if I can do it in a more HTML-fashion I would think that would be better.
I used vs 2008 for coding this and in my IDE here at the office I change the CONNECTION STRING in the web.config to point to different customer databases. Anything I can do in the WEB.CONFIG that the .aspx page can pickup???
View 14 Replies
Nov 15, 2010
I would like to load UserControl dynamically from DLL in the bin directory.
The dll contains several usercontrols which dynamically create webcontrols within them.
I do not have Virtual Path of the UserControls to use in LoadControl(String virtualpath) and LoadControl(Type, object[]) does not work(why the heck is it there in the first place anyways).
provide me some sample code which takes either the path of dll or assembly name "ServerControls" to load usercontrol "UserControl1" dynamically into placeholder "PlaceHolder1"
View 1 Replies
Dec 16, 2010
Can we have the Masterpage loaded dynamicallu. I have a page that must be used in 2 different scenarios ie., using two different master pages.
View 2 Replies
Feb 16, 2011
So I'm trying to dynamically load a usercontrol into a placeholder in another usercontrol inside a updatepanel.
basically I've got this markup:
<asp:UpdatePanel ID="upPopup" runat="server">
<ContentTemplate>
<UC:Popup runat="server" ID="UC_Popup" />
</ContentTemplate>
</asp:UpdatePanel>
And then this markup inside that usercontrol (Popup):
<div id="modal">
<asp:PlaceHolder ID="phPopupPlaceholder" runat="server"></asp:PlaceHolder>
<asp:Label ID="lblModal" runat="server"></asp:Label>
</div>
In the codebehind of the popup usercontrol I have:
public void Show(UserControl control) {
this.phPopupPlaceholder.Controls.Add(control);
this.lblModal.Text = "Loaded";
}
And I call this show method elsewhere with:
Popup.show(new MyUserControl());
Nothing loads into the placeholder though.
But in the show method I can load regular server-controls fine like this:
this.phPopupPlaceholder.Controls.Add(new Label(){ Text = "Label!" });
Can anyone explain to me why regular controls are loaded fine, but my usercontrol isn't loaded?
View 1 Replies
Mar 16, 2011
I want to load the partial views when I click on the hyperlink, in my case I am loading both the partial views and then I am showing or hiding depending the parital views.
<script
type="text/javascript">
$(document).ready( [code].....
View 1 Replies
Aug 2, 2010
I am new to .NET. I want to load data from my table to listbox at runtime.
View 4 Replies
Jan 19, 2011
i have a BaseMasterUserControl.ascx and i have create a another ChildUserControl1.ascx
and ChildUserControl2.ascx, both are inherit from a BaseMasterUserControl.ascx.
i have hosted the BaseMasterUserControl.ascx in an aspx page. At runtime i am deciding
which usercontrol should be load. so i am loading a specific usercontrol dynamically and
assigning it to baseusecontrol but content are not visual, is this possible?
Code:
[code]....
View 2 Replies
Feb 18, 2011
I need to dynamically access some SQL tables hopefully using the Entity Framework. Here's some pseudo code:
var Account = DB.Accounts.SingleOrDefault(x => x.ID == 12345);
which will return me an Account object and this contains some fields called "PREFIX", "CAMPAIGN ID" and further information about the accounts are stored in separate SQL tables with the naming convention of PREFIX_CAMPAIGNID_MAIN.
The tables all have the same fields so I was thinking of creating a new Entity that isn't mapped anywhere and then dynamically loading it, like so:
var STA01_MAIN = new MyAccount(); // my "un-mapped" entity
DB.LoadTable('STA01_MAIN').LoadInto(STA01_MAIN);
I can now get anything about the STA01_MAIN account: STA01_MAIN.AccountId. So my question is: how do I access these tables using the Entity Framework?
View 1 Replies
Sep 22, 2010
I have a table where each cell contains an ImageButton, with an iterative ID:
[Code]....
I am then trying to assign a URL to each imagebutton dynamically in a separate code file
[Code]....
Everything compiles, but when I run this I throw a Null Reference Exception: {"Object reference not set to an instance of an object."}
View 4 Replies
Aug 25, 2010
i would like to load a banner on to the page based on the registration count we have in the DB. if the registration count is >70, i will have to load banner2 on to the page. i am doing like this On the webForm.aspx
<img src="images/banner1.jpg"
runat="server"
id="imgs"/>
in the code behind
protected void Page_Load(object sender,
EventArgs e){
if (!Page.IsPostBack)
{
if(isSessionOneFilled())
{
imgs.Src = "images/banner2.jpg";
}
}
}
The above code works. is it Good Programming to load html files from codebehind? is there any alternative way? how does this impact when internet speed is slow?
View 1 Replies
Jun 25, 2013
Yesterday i asked from u 'Adding-WebUserControl-to-the-page-or-panel-by-client-side-code'.
from scratch it do'snt work properly. but today I downlowded again. its work rightly.
but it just show one control on it (just show lblMessage).
How Can i shows any number of controls on the WebUserControl. ex: button, picture, ...?
View 1 Replies