Listbox'da Seçilen Değerin Değişmesiyle Cross-Page Postback

2 Eylül 2008, Salı, 07:59

0 Yorum RSS comment feed

ListBox nesnesinin bir Button nesnesinde olduğu gibi bir PostBackUrl özelliği yoktur. Ancak kullanıcıları, ListBox içersinden bir değer seçtirip, ardından bir Button'a basarak farklı bir sayfaya postback yaptırabiliriz.

Ama aşağıdaki örnek sayesinde bir ListBox'ın OnSelectedIndexChanged event'i ile kullanıcının seçtiği değeri farklı bir sayfa postback edip orda göstereceğiz.

001Select a language:<br />
002<asp:ListBox ID="ListBox1" runat="server">
003 <asp:ListItem Value="TR" Text="Türkçe" />
004 <asp:ListItem Value="DE" Text="Deutsche" />
005 <asp:ListItem Value="EN" Text="English" />
006</asp:ListBox>

001public ListBox TheListBox
002{
003 get
004 {
005  return ListBox1;
006 }
007}
008protected void Page_Load(object sender, EventArgs e)
009{
010 PostBackOptions options = new PostBackOptions(ListBox1);
011 options.ActionUrl = "SecondPage.aspx"; 
012
013
014 string s = Page.ClientScript.GetPostBackEventReference(options);
015 ListBox1.Attributes["onchange"] = s;
016}

001<%@ PreviousPageType VirtualPath="~/Default.aspx" %>

001protected void Page_Load(object sender, EventArgs e)
002{
003 if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
004 {
005  Response.Write("You selected " + PreviousPage.TheListBox.SelectedValue);
006 }
007}


CrossPagePostBack.rar (18,07 kb)

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Programlama | C# | Asp.Net | Deneyimler & Tecrübeler
,

Yorum ekle

(gözükmeyecek) (Gravatar simgenizi gösterecek)  

biuquote
  • Yorum
  • Canlı önizleme
Loading



Powered by BlogEngine.NET 1.4.0.0 & Development by Emrah ÇETİNER