|
Hi,
I try to create a CompositeDataBoundControl based custom control like this MSDN example.
On first call this page is correctly loaded, CompositeDataBoundControl too.
But on postback the CompositeDataBoundControl is empty.
How can I use automatic ViewState saving and loading for restoring inner table state on postback ?
Loutre Maline
|
|
|
|
|
In this case, you simly a child control such as Label to store data and the Text property of the control can be restored from the ViewState. Another important thing that you should remember is that you only set (or bind) data to the child control after it is added to the parent control.
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
{
table = new Table();
Controls.Add(table);
int count = 0;
if (dataSource != null)
{
SimpleSpreadsheetRow row;
IEnumerator e = dataSource.GetEnumerator();
while (e.MoveNext())
{
object datarow = e.Current;
row = new SimpleSpreadsheetRow(count, datarow);
TableCell cell = new TableCell();
Label lbl = new Label();
cell.Controls.Add(lbl);
row.Cells.Add(cell);
this.Rows.Add(row);
++count;
if (dataBinding)
lbl.Text = datarow.ToString();
}
}
return count;
}
|
|
|
|
|
In fact my table doesn't contains any control. I'm just using Render méthod.
Here is the solution solving my problem :
- Rows must be added to table, even if dataBinding equals false (for creating controls tree), in CreateChildControls.
- Custom Rows (that contains informations to display) must override LoadViewState and SaveViewState methods to save informations.
|
|
|
|
|
loutremaline wrote: Why Table was not saved automatically in ViewState ?
By design, the table does not persist its contents in ViewState.
loutremaline wrote: On postback, dataSource is an object array with only null object. Is it normal ?
Yes, it is.
loutremaline wrote: Is line this.Rows.Add(row); must be executed even if dataBinding equals false ?
Yes. If you don't, the control is not created as exactly as it's last time viewed. Basically, you use the overload the CreateChildControls ( new in the ASP.NET 2) to build the control hierarchy and this method runs when you bind data to the control and on postback. The dataBinding parameter can tell you that you can build the child controls based on the real data source for the first time or from the dummy dataSource. Though the datasource contains all null values, it gives you the most important thing is that the size of the datasource. Based on this size, you can rebuild the table, row and cell....and add child controls like Label to the table and the Text property of the Label can be restored from the ViewState as soon as it is added to the control.
|
|
|
|
|
How can i add blog creation in my asp.net 2003 project.
deepjyoti
|
|
|
|
|
You might want to look around for open source blog software like SubText.
|
|
|
|
|
Hi everyone!
I have combo box and a button in one page,i need,if i select any text in combo box and click the button it should re-direct to another page,that page also in same solution.my all the combo and buttons are html controls.
pls someone help me to that.
|
|
|
|
|
Try to write a subject that says anything specific about the question. Almost every thread here is about someone wanting help with something, so that information is totally useless for distinguishing the thread from others.
If you want to use server code:
In the click event for the button, write:
Response.Redirect(NameOfTheComboBox.SelectedValue);
If you want to use client code:
In the onclick event of the button, write:
window.location=this.form.NameOfTheComboBox.options[this.form.NameOfTheComboBox.selectedIndex].value;
For either to work, the values in the items of the combo box needs to contain the URLs to use for redirection.
---
Year happy = new Year(2007);
|
|
|
|
|
you should change the como box and ... to server controls not html controls...
for doing that right click on your button or combo ... and click "run as server control" ... then double click on your button and go to its code and write response redirect code to connecting it to another page by clicking...
|
|
|
|
|
i'm delvelping a employee information system and i need help when i input my user in my sql table i want to input at the same in excel file i only know for this we use fstream object and i don't exactly know how to do that so anybody know plz help me
OuNy
|
|
|
|
|
Why don't you set your excel sheet to pull data from a query on the server and to automatically refresh when it is opened. Would probably be a little simpler than updating it every time - you'll run into problems if someone has it open when you add a user...
|
|
|
|
|
hi
i hav textbox in one user control and want to access this text box in another user control.
any suggesstion
thanx
Dotnet
|
|
|
|
|
Generally controls are not aware of each other, so it might be easier if you do this from the code in the page instead.
Create a public property in the user control that returns a reference to the textbox. That way you can access it without fiddling around with the control collection of the user control.
---
Year happy = new Year(2007);
|
|
|
|
|
exactly i find some code to get the Text box of User control in another user control but its not running, itsgiving me error..
my code is this .its giving me error in form.controls.
with error :-
"Object reference not set to an instance of an object."
form = (Page)form.FindControl("UserDetail.aspx");
Control txtbx = new TextBox();
foreach (Control ctl2 in form.Controls)
{
if ((ctl2 is UserControl))
{
if (ctl2.ID == "ctlSetKeywords.ascx")
{
FirstName = (TextBox)ctl2.FindControl("txtFirstName");
FirstName.Text = Convert.ToString(ds.Tables[0].Rows[0]["FName"]);
}
}
}
Could u please tell me where i'm making mistake.
Thanx
Dotnet
|
|
|
|
|
That means that the variable form is null.
What does the variable contain from start? Why are you using FindControl to try to get a reference to the page?
---
Year happy = new Year(2007);
|
|
|
|
|
then how would i get the Page and how would i find the Controls under it.
Dotnet
|
|
|
|
|
aavesh wrote: then how would i get the Page
You are in the page. All events for a page are methods in the class for the page.
aavesh wrote: how would i find the Controls under it.
There are references in the page for all server controls in the page. The reference has the same name as the id of the control.
---
Year happy = new Year(2007);
|
|
|
|
|
I am using dot net 2003.
Can I export html page to pdf file without using any code behind language.?
I want to use only aspx coding to perform export.
|
|
|
|
|
how can i design a feedback form interface like this in code project so that i can extract the data from the database in the similar style as i had posted(earlier i had tried with a multi line textbox.but when i extract the data from the database ,all data came in the form of continuious line..no indentation style exists. how can i do this..)
thanks in advance
pradip kishore
|
|
|
|
|
Hi,
i work in Crystal Report. if i have more columns that we can not put them in one page what should we do????
can anybody help me?????????plz
|
|
|
|
|
hi,
can anyone tell me where will we use IEnum interface? i know IList, Idictionary interfaces. but don't know about IEnum & Iclone inteface.
i aprreciate if anyone can tell me about these two
thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
There are no IEnum or IClone interfaces in the framework. Is it IEnumerable and IClonable that you mean?
IEnumerable is used for classes that can be iterated, like arrays, lists and collections.
IClonable is used for classes that supports cloning. That means that the class can produce a copy of itself.
---
Year happy = new Year(2007);
|
|
|
|
|
hello,
I am developing a search page.So I want to have a query builder in my application.The user will be provided with 3 textboxs and as he enters keywords into the fields I want to show him the query.How to go abt this.
Kindly send me feedback
Thanking you,
Raghuvarma.
|
|
|
|
|
Scenario: In database I have 2 columns one is id and other is number coloumn.in number column I will store 0,1 and 2 values. When I am binding this to datagrid I want to display images in the place of 0,1 and 2. For 0=Triangle, 1=Squere and 2=Circle.
plaz let me know
|
|
|
|
|
hi
try this:
when you load the data into the datagrid, you can use the item_databound event to change the number to the image it self, try something like this:
e.item.cells(3).text = replace(e.item.cell(3).text,""
hope this will give u some idea
thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|