|
Create an interface that contains only the properties that you wish to access. Then you have the Page class implement that interface.
Now you can cast the controls' this.Page to the interface, and access you property through it.
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn. What you don't know. We teach
|
|
|
|
|
Hi,
I have populated a few dropdown boxes in runtime and these boxes are bind to a objectdatasource. When I click the Formview's insert button, it posts back to server, and all the items inside the dropdownboxes are disappearing.
How could I protect the values of these boxes in runtime even post back occurs. I tried to define a conditional statement to control to post back as (if not page.ispostback Then), it didn't work out too. All I need is to have the values for the dropdownboxes regardless of if postback occurs or not.
If you know the answer, would you please let me know.
Thank You.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Doesn't ViewState preserve it automatically?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
All the world's a stage,
And all the men and women merely players.
They have their exits and their entrances;
And one man in his time plays many parts... --William Shakespeare
|
|
|
|
|
Thanks for responding. The formview's viewstate is already enabled. I am still looking for a solution.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Vasudevan Deepak Kumar wrote: Doesn't ViewState preserve it automatically?
NO. If OP is creating the control in any event after viewstate is loaded, it's viewstate won't be preserved.
|
|
|
|
|
Web applications are stateless. When you create dynamic controls, ASP.NET won't be able to maintain it's viewstate. Dynamic controls has to be recreated each time page posts. Use OnInit or any event which fires before viewstate is saved to create your dynamic controls.
|
|
|
|
|
Thanks for responding. I never thought that it would be such painfull to deal dynamic controls in asp.net. I placed this dropdownboxes inside the formview and I have populated them in runtime and they are bind to objectdatasource.
The values returns nothing when I try to populate them in Page_Init event. It can't find the control (Formview1.FindControl("GetYear")) returns nothing. OnInit requires an event argument. How coudl you define an event for OnInit inside an aspx page. Would you give me an example.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Hi all, I have a little problem I have a gridview with paging and sorting, all work well except when I change the page then the gridview lost the sorting and it put again by default sorting.
Any idea how maintein the sorting when I change of page?
I send you my code, thanks for all.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Not Page.IsPostBack Then
EnlazarDataGrid()
gridView.Columns(0).SortExpression = True
End If
Catch ex As Exception
End Try
End Sub
Private Property GridViewSortDirection() As String
Get
Return IIf(ViewState("SortDirection") = Nothing, "ASC", ViewState("SortDirection"))
End Get
Set(ByVal value As String)
ViewState("SortDirection") = value
End Set
End Property
Private Property GridViewSortExpression() As String
Get
Return IIf(ViewState("SortExpression") = Nothing, String.Empty, ViewState("SortExpression"))
End Get
Set(ByVal value As String)
ViewState("SortExpression") = value
End Set
End Property
Private Function GetSortDirection() As String
Select Case GridViewSortDirection
Case "ASC"
GridViewSortDirection = "DESC"
Case "DESC"
GridViewSortDirection = "ASC"
End Select
Return GridViewSortDirection
End Function
Protected Function SortDataTable(ByVal pdataTable As DataTable, ByVal isPageIndexChanging As Boolean) As DataView
If Not pdataTable Is Nothing Then
Dim pdataView As New DataView(pdataTable)
If GridViewSortExpression <> String.Empty Then
If isPageIndexChanging Then
pdataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection)
Else
pdataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GetSortDirection())
End If
End If
Return pdataView
Else
Return New DataView()
End If
End Function
Protected Sub gridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Try
gridView.Columns(0).Visible = True
Dim Comunidad As Integer
ViewState("Comunidad") = Util.Usuario.IdComunidad
If Util.Usuario.AdminUser = 1 Then
Comunidad = ViewState("Comunidad")
Else
Comunidad = Util.Usuario.IdComunidad
End If
Dim Propietario1 As DataTable = Propietarios.ObtenerPropietarios(Comunidad)
gridView.DataSource = Propietario1
GridViewSortExpression = e.SortExpression
Dim pageIndex As Integer = gridView.PageIndex
gridView.DataSource = SortDataTable(CType(gridView.DataSource, DataTable), False)
gridView.DataBind()
gridView.PageIndex = pageIndex
gridView.Columns(0).Visible = False
Catch ex As Exception
End Try
End Sub
Protected Sub gridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gridView.PageIndexChanging
Try
gridView.Columns(0).Visible = True
gridView.PageIndex = e.NewPageIndex
EnlazarDataGrid()
gridView.Columns(0).Visible = False
Catch ex As Exception
End Try
End Sub
|
|
|
|
|
Hello!
I have seen this problem before and i have not found any better solution than to save the sortexpression value in a session variable.
Every time the sortexpression is not null, save it to the session, and use the session when the sortexpression is null.
somewhere i saw that this is a bug in the gridview that is exposed when you are databinding from codebehind, but it could be a rumor.
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn. What you don't know. We teach
|
|
|
|
|
Dreamweaver is the web development tool i use, so I guess I should be using php. But from what I heard php and asp.net are similar. I'm more comfortable with the .net suite and I was wondering because of that, should I start doing dhtml in there, or keep with dreamweaver. I mean php can't be that hard, just which one is better overall?
|
|
|
|
|
|
I have a composite server control and I create some dynamic controls in it, like so:
public class MyControl : CompositeControl
{
private Panel panel;
protected override void CreateChildControls()
{
Controls.Clear();
panel = new Panel();
panel.ID = "Panel1";
panel.SkinID = "Panel1"
Controls.Add(panel);
}
protected override void Render(HtmlTextWriter writer)
{
panel.RenderControl(writer);
}
}
The said server control is placed on a page which uses a stylesheet theme, which has a skin file containing a declaration for a Panel skin, like so:
<asp:Panel SkinID="Panel1" runat="server" BackImageUrl="top-panel.gif"></asp:Panel>
However, the skin is never applied... Am I missing something or doing something wrong? Perhaps CreateChildControls override is a bad place to do that?
|
|
|
|
|
Hi all
Im trying to use google base file for my web site,i thought to put a schedule for that file,(which provide by google base feed),so i created the DTS for this everytime error as "Failed" and "We didnt understand ur delimeters" ,so what is the best way to create google base class,and is there and example to this pls give me help.
Thanks,
|
|
|
|
|
Hi:
Can any one tell me how to convert Dataview into datatable on Dotnet2003.
Thanks
suresh
|
|
|
|
|
DataTable dt = theDataView.Table
|
|
|
|
|
hi i would like to know is it possible that i use apachi webserver for asp.net application?
and necessary to install .net framework?
I will do my best?
Integrated Solutions, Bikaner (Raj.), India
|
|
|
|
|
You need IIS for an asp.net webiste I think
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
|
I can only find 3rd party controls.
Any help would be great
thanks
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Ive got an Onclick event which has the following code in:
ViewState["items"] = lb1.SelectedItem.Value;
Response.Redirect("Page.aspx?sql=items");
on the pageload it should then display the values chosen from listbox if the page has posted back.
However when I click the Button it shows an Object Reference Error for the following line:
ViewState["items"] = lb1.SelectedItem.Value;
why is this?
thanks
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Seems to me that there there are no selected items when the button is click'ed.
if(lb1.SelectedItem != null)
{
ViewState["items"] = lb1.SelectedItem.Value;
}
If the listbox allso has multiselect = true, you will allso get a problem.
if so you should use
string strValues = "";
foreach(ListItem li in lb1.Items)
{
if(li.Selected)
{
strValuse+=li.Value;
}
}
Hope it helps
Thomas
modified on Monday, October 6, 2008 10:31 AM
|
|
|
|
|
Thanks for the post but it doesnt work Ive got
string strValues = "";
foreach (ListItem li in listbox1.Items)
{
if (li.Selected)
{
strValues += li.Value;
}
}
Session["items"] = strValues;
in the onclick event and then on pageload I have:
lbitems.Text = "Items selected: " + Session["items"].ToString();
The label is shown as blank.
I really dont understand why this is happening, very weird!
Any more help would be great
thanks
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Session is not updated at the time you go to the next page so you should us
ViewState or HttpContext.Current.Items["somevalues"]
If you have multiselect, you should splitt the valuse by somthing, so you can retrive them
Something lik:
if(listbox1.SelectedItem != null){
string strValues = "";
for (int i = 0; i < listbox1.Items.Count;i++)
{
if(listbox1.Items[i].Selected){
strValues += listbox1.Items[i].Value + ",";
}
strValues = strValues .Remove(strValues.Lenght - 1, 1);
}
HttpContext.Current.Items["theItemsValues"] = strValues;
}
on the pageload of the new page:
if(HttpContext.Current.Items.Contains("theItemsValues")) {
lbitems.Text= "Items selected: " +HttpContext.Current.Items["theItemsValues"].ToString();
}
If you then actually needs the items values:
string[] strListOfValues = HttpContext.Current.Items["theItemsValues"].ToString().Splitt(',');
modified on Tuesday, October 7, 2008 5:45 AM
|
|
|
|
|
Thanks, I will try that tomorrow and will get back to you, thnaks for the help!
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|
|
Still the problem persists.
This is one of the strangest I have ever seen. Cant understand it.
Deliver yesterday, code today, think tomorrow.
"http://www.heuse.com/cphumor.htm"
|
|
|
|