My controls are dynamically generated when the dropdownlist is changed by user. They values are loaded from the database. How to display progressbar during the generation of control?
You can add download image on the form. When user will change item in dropdownlist call the event onchange with javascript. There is example for adding handler:
protected void Page_Load(object sender, EventArgs e)
{
dropdownlist1.Attributes.Add("onchange", "document.getElementById(\"loading_image\").style.visibility = \"visible\";");
}
Before that you must add image on the form:
<img style="visibility:hidden;" src="imageurl" runat="server" id="loading_image" />
if(combobox.text=="type selected value")
{
load the progress bar here..
}
After the user makes the selection, insert an <img> tag with an animated .gif progress bar. When the controls are returned to load onto the page, use javascript to delete the <img> tag and insert your controls.
For showing actual progress you need a Context-Sensitive progress bar. Here is the article that is showing how to show actual progress through ajax of server side operations.
Related
I have <td id="StatusPreview" runat="server"></td> and it gets populated by a js function by:
document.getElementById('StatusPreview').innerHTML = Ext.getCmp('TYComboEdit').getRawValue();
Now, I would like to change the content of the td in c# when a button is clicked.
I created the following method:
protected void hiddentoggletofrenchBackend(object sender, DirectEventArgs e)
{
this.StatusPreview.InnerHtml = "aaaaa";
}
It does not change the content on the td. However, if I place an alert after setting the InnerHtml it alerts aaaaa even though the td content has not changed to reflect this. If I place an alert before setting the InnerHtml the alert is blank.
How can I change the InnerHtml of the div?
Thank you!
UPDATE:
If I change the html to <td id="StatusPreview" runat="server">q</td> the alert shows q if it is placed before setting InnerHtml, and switches to aaaaa if placed after.
It is as if InnerHtml is taking the value on pageload, not the current value.
To update an ASP.NET control during a DirectEvent, you should call the .Update() method.
protected void hiddentoggletofrenchBackend(object sender, DirectEventArgs e)
{
this.StatusPreview.InnerHtml = "aaaaa";
this.StatusPreview.Update();
}
Adding runat=server to a td element turns it into a HtmlTableCell control. The relevant property to set the inner text on this control is InnerText.
As this is a server side control, any change is only going to happen after postback to the server. That would mean the entire page is reloaded and re-rendered. You can examine requests to the server and the server responses with the free tool Fiddler. Assuming a postback is actually happening, are you sure you're not overwriting the new inner text with JavaScript which runs on page load?
Do you even need to do a postback for this? If "aaaaa" is not a placeholder for what will become a database or some other lookup, I would render the alternate text into a hidden div or into some JavaScript and do the text change entirely in JavaScript.
I want to load HTML content in a panel when a button is clicked. The content is generated from the c# code by fetching the database.
Currently I have to load the content on page load in the panel and make panel visible on button click. But that makes the website speed very low. So please tell how can I load html content on demand in panel?
The code to be written in the panel on button click should be this:
<p><%=databaseFuncs.getName() %></p>
So as you can see I want to things to happen on Button Click: First the C# code should be executed than it should be encapsulated in paragraph tag and then written to the panel. One by one for all database rows this should be repeated. Please help.
Also note than I don't want to use custom asp.net controls.
Just make the
databaseFuncs
public and
databaseFuncs.getName()
public and your code should work...
If the code is inside runat="server" then just use '#' instead of '='
I wrote a ASP.NET Application and it run in IIS7 of a Server. If I open this webform in my Browser and show me the Sitecode I see this...
I have many Controls how Buttons,Labels,TextBoxes and a ListView. I try to deactivate ViewState in the web.config but if I deactivate this my Application don't run correctly. What can I do?
Deactivate only the controls that not need the viewstate.
To do that you need to understand what the viewstate is.
Viewstate is where the page save and remember the values of the controls to have them after a post back. Remember that, the viewstate is used after a post back.
So actually you have two times the same data, but only the viewstate is post back the previous data and code behind can be use that data.
So the main question is, what controls do you need to be remember what you have fill them in, or what controls need to remeber the previous state of them.
Lets see a simple Literal with EnableViewState on and off.
ViewState ON
<asp:Literal runat="server" EnableViewState="true" ID="txtLiterar">
Now if you place a text on this literal the text is also saved on viewstate and on code behind you can do that.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtLiterar.Text = "Hello There";
}
}
So after the post back the Literal still have its content, and you can avoid to fill it again, because the viewstate have it and automatically fills it again.
ViewState OFF
<asp:Literal runat="server" EnableViewState="false" ID="txtLiterar">
Now if you place a text on this literal the text is not saved on view state and on code behind you add it as.
protected void Page_Load(object sender, EventArgs e)
{
txtLiterar.Text = "Hello There";
}
So the different is that you need to always fill that control with data on every post.
Where the viewstate is needed most.
The most needed part of the viewstate is when you fill a dropdown list. There you have a databind and code behind need to remember the values to place on the SelectValue the correct one.
Its also needed on GridView and other controls like that because is keep the previous page and other information's when you paging your data.
So you can close on most of your controls the viewstate - on that controls that you can fill them again on every post back, and on that controls that not need to remeber the previous state.
More to read:
How to optimize class for viewstate
Determine size of ASP.NET page's viewstate before serving page
Limiting view state information on AJAX calls
I have an Update Panel that contains an image and a button. Image control displays one image at a time when clicked on "Next Image" Button and previous image on clicking "Previous Image" button. Code sample is something like this
protected void btnNext_Click(..)
{
Image1.ImageUrl=getNextImageFromDatabase();
UpdatePanel1.Update();
}
protected void btnPrevious_Click(..)
{
Image1.ImageUrl=getPreviousImageFromDatabase();
UpdatePanel1.Update();
}
Now what I want to know is that is there any way I can slide image or whatever content in update panel to left when clicked on "Next Image" and similarly to right when clicked on "Previous Image"? Is there any way using AjaxToolKit or JQuery?
You can you use the jquery fadeIn fadeOut methods which will look like a slide effect
See example here http://api.jquery.com/promise/#example-1
With Jquery you can simply animate margin-left to negative values, so Image would disapear. I personaly use this solution:
User clicks on next/prev button
Show loading image (a gif)
Create image (var img = new Image()) in javascript
set onload action for that image to move old one to left/right and append new image etc.
get next/prev image url
assign src of the created image, so when it's loaded the onload action is executed.
AjaxToolkit might not be the cleanest solution in this case. You will probably need to make some simple service that returns nex/prev image url, but that's only few lines of code...
On my master page , I have "Search textbox" and "Search Button".
On My content page , I have a "User Control" which has a "GridView".It shows some data about Vendors.
Also, on this User Control's Page Load, i have code written to display all vendors in GridView.
Now, when user enters Vendor Number in "Search textbox" , and hits "Search Button" , i want to handle this event inside my User Control.
How to do this ?
Please help me. Thanks in advance.
Note : i know how to handle the event in content page but not sure how to handle it inside user control placed on content page.
You just need to add logic that passes in the Search Parameters to the User Control.
On the User Control, make a public method to Bind the grid that takes in the search text
public void BindGrid{string searchText)
{
//get datasource with the searchText used as a Where, or whatever suits your current situation
//bind grid
}
Then, on the MasterPage, you should have something like
protected void btnSearch_Click(object sender, EventArgs e)
{
UserControl1.BindGrid(tbSearchText.Text);
}
You just need to make sure that your UserControl doesn't bind data on the PageLoad event if IsPostBack is true. Otherwise, you'll be binding data twice.
If you know how to handle the event in the content page, you can apply that same approach to the control. It will still be the content page that wires the control's handler to the master page's event, since the content page is the entity that knows and can access both the master page and control.