在這裏,我得到了查找文本的ID的解決方案,選擇通過HTML按鈕標籤點擊
<input type="button" id="save" value="submit" onclick="submitpage()" />
然後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>
在C#代碼我用這樣的.. 。
[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";
}
有人做過.. 希望這將是對某一l相關ike me..hmm ...
你爲什麼不用asp.net頁面替換你的html頁面,並給你的輸入類型賦予屬性runat =「server」? –
實際上,輸入類型是通過Jquery代碼動態創建的。 – Srikanth
在這種情況下,您可能需要將您動態創建的控件註冊到asp.net表單。 –