2015-02-23 20 views
6

kullanarak Özellikleri: Ben bu iki veri özelliklerini almak istiyorum benim OnCheckedChanged halindeHTML5 nasıl alınır veriye * Bir asp benim formda onay kutusu C#

<asp:CheckBox id="option" runat="server" OnCheckedChanged="checkChange" data-attributeA="somevalue1" data-attributeB="somevalue2" AutoPostBack="true" />` 

.

protected void checkChange(object sender, EventArgs e) {} 

Bunu nasıl yaparım?

+1

olası yinelenen [Nasıl özel metin kutusu ASP.Net içinde niteliklerini erişebilir? ] (http://stackoverflow.com/questions/12785946/how-can-i-access-custom-textbox-attributes-in-asp-net) – musefan

cevap

8

@musefan tarafından paylaşılan linkte aynı yaklaşım sizin için çalışacaktır.

Ben CheckBox yarattık: Bu değişiklik yüzden,

protected void CheckBox1_CheckedChanged(object sender, EventArgs e) 
    { 
     String customAttr1 = CheckBox1.Attributes["dataAttributeA"].ToString(); 
     String customAttr2 = CheckBox1.Attributes["dataAttributeB"].ToString(); 

     Response.Write("<h1> Custom Attributes A and B = " + customAttr1 + " " + customAttr2); 

    } 

Ve sonunda true CheckBox AutoPostBack özelliğini belirledik: Sonra

<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" dataAttributeA="Test Custom Attr A" dataAttributeB="Test Custom B" Text="Check it or dont" AutoPostBack="True" /> 

değiştirilen olayı işlemek için bir yöntem Etkinlik tıklandığında en kısa sürede tetiklenir.

beklediğim sonucu

almış

Özel Ayrıntılar A ve B = Testi Özel Attr A Testi Özel B

İlgili konular