最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Get html input values in server side in asp.net - Stack Overflow

programmeradmin1浏览0评论
    <asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="Server">  
     <script type="text/javascript">
      $(function () {
                    $("#slider-range").slider({
                        range: true,
                        min: 0,
                        max: 100,
                        values: [0, 75],
                        slide: function (event, ui) {
                            $("#value").val("" + ui.values[0] + " - " + ui.values[1]);
                        }
                    });
                    $("#value").val("" + $("#slider-range").slider("values", 0) +
                    " - " + $("#slider-range").slider("values", 1));
                });
      </script>
    </asp:content>

I am using this code for a slider in my asp page. Now the value in displayed in the Html input.

      <input type="text" id="value" style="border: 0; font-weight: bold;" />

it is displayed as 0-75. How can I get both the values (0,75) separately in my server side so that i can write the values in database.

How to change the code so that in my server side I can asign values to 2 variables. The slider contains min value(0) and max value(75)[selected by users].

var a= 0; var b= 75;

    <asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="Server">  
     <script type="text/javascript">
      $(function () {
                    $("#slider-range").slider({
                        range: true,
                        min: 0,
                        max: 100,
                        values: [0, 75],
                        slide: function (event, ui) {
                            $("#value").val("" + ui.values[0] + " - " + ui.values[1]);
                        }
                    });
                    $("#value").val("" + $("#slider-range").slider("values", 0) +
                    " - " + $("#slider-range").slider("values", 1));
                });
      </script>
    </asp:content>

I am using this code for a slider in my asp page. Now the value in displayed in the Html input.

      <input type="text" id="value" style="border: 0; font-weight: bold;" />

it is displayed as 0-75. How can I get both the values (0,75) separately in my server side so that i can write the values in database.

How to change the code so that in my server side I can asign values to 2 variables. The slider contains min value(0) and max value(75)[selected by users].

var a= 0; var b= 75;

Share Improve this question edited Sep 12, 2011 at 12:03 Davide Piras 44.6k10 gold badges103 silver badges150 bronze badges asked Sep 12, 2011 at 12:02 MarkMark 2,76015 gold badges59 silver badges87 bronze badges 1
  • Have you tried to add runat="server" attribute and access the control by its ID? – sll Commented Sep 12, 2011 at 12:04
Add a ment  | 

2 Answers 2

Reset to default 3

You could just do something like:

string[] vals = Request.Form["value"].Split('-');
int a = int.Parse(vals[0]);
int b = int.Parse(vals[1]);

Since you are using ASP.NET WebForms,not MVC, i strongly remend that you stick to the ASP.NET Controls approach. Instead of using pure html, it is easier to use the TextBox wrappers provided by ASP.NET:

<asp:TextBox runat="server" ID="value"></asp:TextBox>

The rest of the code stays the same.

发布评论

评论列表(0)

  1. 暂无评论