开发者

Implement a custom ASP.NET ListControl that post back data with javascript

开发者 https://www.devze.com 2023-04-12 04:15 出处:网络
I\'m writing a custom server control inherited from ListControl. I\'m able to change the rendering of the control (overriding the Render method), using a \"li\" with a custom CSS instead of using the

I'm writing a custom server control inherited from ListControl. I'm able to change the rendering of the control (overriding the Render method), using a "li" with a custom CSS instead of using the normal tag "option", but how can i send the selected data back to the control? I've implemented the selection using javascript. I suppose that i've to use javascript to send to the control the selected value, but i don't know how. If anyone could bring me in the right way, i'll appreciate.

Th开发者_如何学Canks in advance


use some jquery ajax

$.ajax({  
         type: "GET",  
         url: "process_me.aspx?value=" + $("#id-of-hidden-value-of-list").val(),  
         success: function(){  
            //success (not finished)
            alert("woot!")
            }  
         });  

i mean that's quick and dirty. And use Request.QueryString collection to pick up the value in the code-behind.

You could instead implement a hidden control in the render method. ASP.NET fan boi's would have you implementing IPostBackEventHandler.

You could keep it simpler, rendering a plain html hidden and use the Request.Form collection on postback.

Response.Write("<input type='hidden' name='list-value'>");
..

document.forms[0].list-value.value = selectedValue;
document.forms[0].submit();

.. 

if(Request.Form["list-value"]) != "" { // do something }

And an alt to ajax is some jquery / javascript that either writes the selected valu to a hidden or the form's querystring before submitting it (which is what that ajax code is doing).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号