0

I have saved input (text,checkbox,dropdownlist) in one html page, and am loading that in asp:panel, after loading users can enter values in that. Now by Clicking Asp:button i have to find that input types and save to database, how can it achieved.

the input code will be in this format .

<label style="left: 46px; top: 73px; position: relative;" id="Llb1" onmouseup="MLup(this.id)" class="ui-draggable" onmousedown="MLdown(this.id)"> Enter the value </label>
<input style="left: 170px; top: 113px; position: relative;" id="T1" onmouseup="mUp(this.id)" class="ui-draggable"  onmousedown="mDown(this.id)" value="" type="text">

This input types i have to find those ids, and text... how can it possible..

4
  • Why don't you replace your html page with asp.net page and give attribute runat="server" to your input types? Commented Oct 17, 2012 at 10:48
  • Actually that input types was dynamically created through Jquery code. Commented Oct 17, 2012 at 10:49
  • In that case you might need to register your dynamically created controls to asp.net form . Commented Oct 17, 2012 at 10:51
  • Request.Form will do the trick. stackoverflow.com/questions/9337418/… Commented Oct 17, 2012 at 11:02

3 Answers 3

1

First of all, you can't get label's value on server. For getting dynamic textbox value you need to assign name attribute on it and get value on postback from Request.Form collection by that name.

Sign up to request clarification or add additional context in comments.

Comments

0

You have at least two options to achieve it.

  • Create some hidden fields also along with the fields you are creating and put the field type value and other required meta data in the hidden fields. When you post the form, these hidden fields will serve you the metadata about the form which you can use to properly insert it in database.

or

  • When you dynamically create the control, inform the server about it using ajax request so that server has prior knowledge of these fields. You can store this information in session and when the form post back, you can use it to obtain the data from request object.

In either case, you have to use the raw request object to get the values of the fields as asp.net will not parse those fields which were not present on the page as they will not be the part of view state.

It is a good idea to post the entire form using ajax rather then posting it in normal way. This way, you could be sure that only the dynamic data is posted.

Comments

0

Here i got a solution for finding the id of text,select, labels through html Button click

 <input type="button" id="save" value="submit" onclick="submitpage()" />

then on submitpage

<script type="text/javascript">
          function submitpage() {
              var completeids = new Array();
              var completevalues = new Array();
              var completetype = new Array();
              var completeselected = new Array();
              var labelvalues = new Array();
             // var name = "abc";
              var name = document.getElementById('<%=username.ClientID %>').innerHTML
              $('input[type="text"]').each(function () {
                  completeids.push($(this).attr('id'));
                  completetype.push('TEXTBOX');
                  completevalues.push($(this).attr('value'));
                  completeselected.push('no');

              });
              $('label').each(function () {
                  completeids.push($(this).attr('id'));
                  completevalues.push($('label[id= ' + $(this).attr('id') + ']').html());
                  labelvalues.push($('label[id= ' + $(this).attr('id') + ']').html());
                  completetype.push('LABEL');
                  completeselected.push('no');

              });
              $('select').each(function () {
                  completeids.push($(this).attr('id'));
                  completevalues.push($(this).val());
                  completetype.push('DROPDOWN');
                  completeselected.push('no');

              });
              $('input[type="checkbox"]').each(function () {
                  completeids.push($(this).attr('id'));
                  completevalues.push($('label[for=' + $(this).attr('id') + ']').html());
                  completetype.push('CHECKBOX');
                  completeselected.push($(this).attr('checked'));

              });
              $('input[type="radio"]').each(function () {
                  completeids.push($(this).attr('id'));
                  completevalues.push($('label[for=' + $(this).attr('id') + ']').html());
                  completetype.push('RADIOBUTTON');
                  completeselected.push($(this).attr('checked'));

              });
              $('input[type="file"]').each(function () {
                  completeids.push($(this).attr('id'));
                  //completevalues.push('not yet done');
                  completevalues.push($(this).attr('value'));

                  completetype.push('FILE');
                  completeselected.push('no');

              });

              var loc = window.location.href;
              $.ajax({
                  type: 'POST',
                  url: loc + "/GetSaved",
                  data: "{getcompleteids :'" + completeids + "',getcompletevalues :'" + completevalues + "',getcompletetypes :'" + completetype + "',getcompleteselected :'" + completeselected + "',getlabelvalue :'" + labelvalues + "',formname:'"+name+"'}",
                  contentType: "application/json; charset=utf-8"

              })
            .success(function (response) {
                alert(response.d);

            })
            .error(function (response) {
                alert(response.d);
            });

          }

    </script>

at c# code i have used like this...

 [WebMethod]
    public static string GetSaved(string getcompleteids, string getcompletevalues, string getcompletetypes, string getcompleteselected, string getlabelvalue, string formname)
    {

        string[] completeids = getcompleteids.Split(',');
        string[] completevalues = getcompletevalues.Split(',');
        string[] completetypes = getcompletetypes.Split(',');
        string[] completeselected = getcompleteselected.Split(',');
        string[] labelvalues = getlabelvalue.Split(',');
         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dynamic"].ConnectionString);
        string FORMNAME = labelvalues[0];
        for (int i = 0; i <= completeids.Length-1; i++)
        {
            con.Open();
                                                                                        //FORM_NAME,     USER_NAME         ,CONTRO_TYPE,             CONTROL_ID,        CONTROL_VALUE,                CONTROL_SELECTED
            SqlCommand cmd = new SqlCommand("INSERT INTO CONTROLS_INFORMATION VALUES('" + FORMNAME + "',' "+formname+" ','" + completetypes[i] + "','" + completeids[i] + "','" + completevalues[i] + "','" + completeselected[i] + "')", con);
            cmd.ExecuteNonQuery();
            con.Close();
        }



        return "successfully";

    }

It was done.. Hope it will be useful to some one like me..hmm...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.