ASP TextBox value assigned in client side not appearing in postback
up vote
0
down vote
favorite
I'm fetching data from database using ajax and jquery to fill the textboxes with some values. The issue is whenever a post back happens all the data which was assigne by jquery gets lost. I've tried almost everything.
I've removed the ReadOnly="true" property from textboxes.
I don't want to use Hidden Fields because I've almost 20-25 text boxes in single page. Is there any another approach to do this.
Jquery Code
$.ajax({
type: "POST",
url: 'Services/Customer.asmx/GetCustomerDetails',
dataType: "json",
data: JSON.stringify({ branchCode: BranchCode, customerCode: CustomerCode }),
contentType: "application/json; charset=utf-8",
success: function (returnedData) {
debugger;
var data = returnedData.d;
$("#txt_CustName").val(data[0].customerName);
$("#txt_AddressCust").val(data[0].address1);
$("#txt_AddressCust1").val(data[0].address2);
$("#txt_CityCust").val(data[0].City);
$("#txt_PinCodeCust").val(data[0].pinCode);
$("#txt_EmailCust").val(data[0].email);
$("#txt_MobileCust").val(data[0].mobile);
$("#txt_ContactPersonCust").val(data[0].contactPerson);
$("#txt_GSTNCust").val(data[0].GSTN);
$("#hdn_CustomerGroup").val(data[0].customerGroup);
}
Please suggest me any solution...
jquery asp.net ajax postback viewstate
|
show 1 more comment
up vote
0
down vote
favorite
I'm fetching data from database using ajax and jquery to fill the textboxes with some values. The issue is whenever a post back happens all the data which was assigne by jquery gets lost. I've tried almost everything.
I've removed the ReadOnly="true" property from textboxes.
I don't want to use Hidden Fields because I've almost 20-25 text boxes in single page. Is there any another approach to do this.
Jquery Code
$.ajax({
type: "POST",
url: 'Services/Customer.asmx/GetCustomerDetails',
dataType: "json",
data: JSON.stringify({ branchCode: BranchCode, customerCode: CustomerCode }),
contentType: "application/json; charset=utf-8",
success: function (returnedData) {
debugger;
var data = returnedData.d;
$("#txt_CustName").val(data[0].customerName);
$("#txt_AddressCust").val(data[0].address1);
$("#txt_AddressCust1").val(data[0].address2);
$("#txt_CityCust").val(data[0].City);
$("#txt_PinCodeCust").val(data[0].pinCode);
$("#txt_EmailCust").val(data[0].email);
$("#txt_MobileCust").val(data[0].mobile);
$("#txt_ContactPersonCust").val(data[0].contactPerson);
$("#txt_GSTNCust").val(data[0].GSTN);
$("#hdn_CustomerGroup").val(data[0].customerGroup);
}
Please suggest me any solution...
jquery asp.net ajax postback viewstate
if you want to keep your data after postback , you need to keep them somewhere on your page (hidden fields , json,...). and it dosnot cost you a lot
– Hamed
Nov 20 at 5:29
Try to use Input control and use as like "Request.Form["name"]" in backend.
– Jitendra Rangpariya
Nov 20 at 5:35
Thanks for your response sir, but will you please clarify it more
– Rohit_Chiki
Nov 20 at 5:40
Ok fine. let me explain as answer.
– Jitendra Rangpariya
Nov 20 at 5:41
yes please......
– Rohit_Chiki
Nov 20 at 5:44
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm fetching data from database using ajax and jquery to fill the textboxes with some values. The issue is whenever a post back happens all the data which was assigne by jquery gets lost. I've tried almost everything.
I've removed the ReadOnly="true" property from textboxes.
I don't want to use Hidden Fields because I've almost 20-25 text boxes in single page. Is there any another approach to do this.
Jquery Code
$.ajax({
type: "POST",
url: 'Services/Customer.asmx/GetCustomerDetails',
dataType: "json",
data: JSON.stringify({ branchCode: BranchCode, customerCode: CustomerCode }),
contentType: "application/json; charset=utf-8",
success: function (returnedData) {
debugger;
var data = returnedData.d;
$("#txt_CustName").val(data[0].customerName);
$("#txt_AddressCust").val(data[0].address1);
$("#txt_AddressCust1").val(data[0].address2);
$("#txt_CityCust").val(data[0].City);
$("#txt_PinCodeCust").val(data[0].pinCode);
$("#txt_EmailCust").val(data[0].email);
$("#txt_MobileCust").val(data[0].mobile);
$("#txt_ContactPersonCust").val(data[0].contactPerson);
$("#txt_GSTNCust").val(data[0].GSTN);
$("#hdn_CustomerGroup").val(data[0].customerGroup);
}
Please suggest me any solution...
jquery asp.net ajax postback viewstate
I'm fetching data from database using ajax and jquery to fill the textboxes with some values. The issue is whenever a post back happens all the data which was assigne by jquery gets lost. I've tried almost everything.
I've removed the ReadOnly="true" property from textboxes.
I don't want to use Hidden Fields because I've almost 20-25 text boxes in single page. Is there any another approach to do this.
Jquery Code
$.ajax({
type: "POST",
url: 'Services/Customer.asmx/GetCustomerDetails',
dataType: "json",
data: JSON.stringify({ branchCode: BranchCode, customerCode: CustomerCode }),
contentType: "application/json; charset=utf-8",
success: function (returnedData) {
debugger;
var data = returnedData.d;
$("#txt_CustName").val(data[0].customerName);
$("#txt_AddressCust").val(data[0].address1);
$("#txt_AddressCust1").val(data[0].address2);
$("#txt_CityCust").val(data[0].City);
$("#txt_PinCodeCust").val(data[0].pinCode);
$("#txt_EmailCust").val(data[0].email);
$("#txt_MobileCust").val(data[0].mobile);
$("#txt_ContactPersonCust").val(data[0].contactPerson);
$("#txt_GSTNCust").val(data[0].GSTN);
$("#hdn_CustomerGroup").val(data[0].customerGroup);
}
Please suggest me any solution...
jquery asp.net ajax postback viewstate
jquery asp.net ajax postback viewstate
asked Nov 20 at 5:10
Rohit_Chiki
134
134
if you want to keep your data after postback , you need to keep them somewhere on your page (hidden fields , json,...). and it dosnot cost you a lot
– Hamed
Nov 20 at 5:29
Try to use Input control and use as like "Request.Form["name"]" in backend.
– Jitendra Rangpariya
Nov 20 at 5:35
Thanks for your response sir, but will you please clarify it more
– Rohit_Chiki
Nov 20 at 5:40
Ok fine. let me explain as answer.
– Jitendra Rangpariya
Nov 20 at 5:41
yes please......
– Rohit_Chiki
Nov 20 at 5:44
|
show 1 more comment
if you want to keep your data after postback , you need to keep them somewhere on your page (hidden fields , json,...). and it dosnot cost you a lot
– Hamed
Nov 20 at 5:29
Try to use Input control and use as like "Request.Form["name"]" in backend.
– Jitendra Rangpariya
Nov 20 at 5:35
Thanks for your response sir, but will you please clarify it more
– Rohit_Chiki
Nov 20 at 5:40
Ok fine. let me explain as answer.
– Jitendra Rangpariya
Nov 20 at 5:41
yes please......
– Rohit_Chiki
Nov 20 at 5:44
if you want to keep your data after postback , you need to keep them somewhere on your page (hidden fields , json,...). and it dosnot cost you a lot
– Hamed
Nov 20 at 5:29
if you want to keep your data after postback , you need to keep them somewhere on your page (hidden fields , json,...). and it dosnot cost you a lot
– Hamed
Nov 20 at 5:29
Try to use Input control and use as like "Request.Form["name"]" in backend.
– Jitendra Rangpariya
Nov 20 at 5:35
Try to use Input control and use as like "Request.Form["name"]" in backend.
– Jitendra Rangpariya
Nov 20 at 5:35
Thanks for your response sir, but will you please clarify it more
– Rohit_Chiki
Nov 20 at 5:40
Thanks for your response sir, but will you please clarify it more
– Rohit_Chiki
Nov 20 at 5:40
Ok fine. let me explain as answer.
– Jitendra Rangpariya
Nov 20 at 5:41
Ok fine. let me explain as answer.
– Jitendra Rangpariya
Nov 20 at 5:41
yes please......
– Rohit_Chiki
Nov 20 at 5:44
yes please......
– Rohit_Chiki
Nov 20 at 5:44
|
show 1 more comment
3 Answers
3
active
oldest
votes
up vote
0
down vote
The value will be reset on each postback, when it is set from the client side.
Below is the way you can do something like,
.ASPX
$(document).ready(function () {
$("#traveller_phone").val("9898948484");
});
<input type="text" class="form-control" name="traveller_phone" id="traveller_phone" />
<asp:Button ID="ClickMe" Text="click me" runat="server" OnClick="ClickMe_Click" />
C#:
protected void ClickMe_Click(object sender, EventArgs e)
{
string phone = Request.Form["traveller_phone"];
}
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
add a comment |
up vote
0
down vote
asp.net textbox control use attribute ClientIDMode="Static" .
Solved your problem try this.
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
add a comment |
up vote
0
down vote
try below code.
.aspx
<script type="text/javascript">
$(document).ready(function () {
$("#txt_name").val("Cory");
});
</script>
<body>
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanelLossHistory" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<input type="text" runat="server" name="txt_name" id="txt_name" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />
<asp:Button runat="server" ID="Button2" Text="DummyPostback" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
string txtName = Request.Form["txt_name"];
}
There are two buttons, one for submitting and second one for dummy postback hit.
Now, the value will not be lost if you click on "dummy" button and if you modify the name and click on "submit" you will get the modified name. I hope this helps.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The value will be reset on each postback, when it is set from the client side.
Below is the way you can do something like,
.ASPX
$(document).ready(function () {
$("#traveller_phone").val("9898948484");
});
<input type="text" class="form-control" name="traveller_phone" id="traveller_phone" />
<asp:Button ID="ClickMe" Text="click me" runat="server" OnClick="ClickMe_Click" />
C#:
protected void ClickMe_Click(object sender, EventArgs e)
{
string phone = Request.Form["traveller_phone"];
}
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
add a comment |
up vote
0
down vote
The value will be reset on each postback, when it is set from the client side.
Below is the way you can do something like,
.ASPX
$(document).ready(function () {
$("#traveller_phone").val("9898948484");
});
<input type="text" class="form-control" name="traveller_phone" id="traveller_phone" />
<asp:Button ID="ClickMe" Text="click me" runat="server" OnClick="ClickMe_Click" />
C#:
protected void ClickMe_Click(object sender, EventArgs e)
{
string phone = Request.Form["traveller_phone"];
}
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
add a comment |
up vote
0
down vote
up vote
0
down vote
The value will be reset on each postback, when it is set from the client side.
Below is the way you can do something like,
.ASPX
$(document).ready(function () {
$("#traveller_phone").val("9898948484");
});
<input type="text" class="form-control" name="traveller_phone" id="traveller_phone" />
<asp:Button ID="ClickMe" Text="click me" runat="server" OnClick="ClickMe_Click" />
C#:
protected void ClickMe_Click(object sender, EventArgs e)
{
string phone = Request.Form["traveller_phone"];
}
The value will be reset on each postback, when it is set from the client side.
Below is the way you can do something like,
.ASPX
$(document).ready(function () {
$("#traveller_phone").val("9898948484");
});
<input type="text" class="form-control" name="traveller_phone" id="traveller_phone" />
<asp:Button ID="ClickMe" Text="click me" runat="server" OnClick="ClickMe_Click" />
C#:
protected void ClickMe_Click(object sender, EventArgs e)
{
string phone = Request.Form["traveller_phone"];
}
edited Nov 20 at 6:15
answered Nov 20 at 5:45
Jitendra Rangpariya
395110
395110
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
add a comment |
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
ok, let me try this solution
– Rohit_Chiki
Nov 20 at 5:48
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I've tried this but it did n't worked for me ...The value gets lost during postback
– Rohit_Chiki
Nov 20 at 6:05
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
I should be work. I have updated my code with full description. Try to create new page and implement as above sample.
– Jitendra Rangpariya
Nov 20 at 6:18
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
Sir, I've tried above code but I don't know why It's not working
– Rohit_Chiki
Nov 20 at 8:23
add a comment |
up vote
0
down vote
asp.net textbox control use attribute ClientIDMode="Static" .
Solved your problem try this.
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
add a comment |
up vote
0
down vote
asp.net textbox control use attribute ClientIDMode="Static" .
Solved your problem try this.
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
add a comment |
up vote
0
down vote
up vote
0
down vote
asp.net textbox control use attribute ClientIDMode="Static" .
Solved your problem try this.
asp.net textbox control use attribute ClientIDMode="Static" .
Solved your problem try this.
answered Nov 20 at 6:32
ravi polara
317111
317111
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
add a comment |
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
Sorry, that did n't work for me
– Rohit_Chiki
Nov 20 at 8:24
add a comment |
up vote
0
down vote
try below code.
.aspx
<script type="text/javascript">
$(document).ready(function () {
$("#txt_name").val("Cory");
});
</script>
<body>
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanelLossHistory" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<input type="text" runat="server" name="txt_name" id="txt_name" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />
<asp:Button runat="server" ID="Button2" Text="DummyPostback" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
string txtName = Request.Form["txt_name"];
}
There are two buttons, one for submitting and second one for dummy postback hit.
Now, the value will not be lost if you click on "dummy" button and if you modify the name and click on "submit" you will get the modified name. I hope this helps.
add a comment |
up vote
0
down vote
try below code.
.aspx
<script type="text/javascript">
$(document).ready(function () {
$("#txt_name").val("Cory");
});
</script>
<body>
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanelLossHistory" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<input type="text" runat="server" name="txt_name" id="txt_name" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />
<asp:Button runat="server" ID="Button2" Text="DummyPostback" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
string txtName = Request.Form["txt_name"];
}
There are two buttons, one for submitting and second one for dummy postback hit.
Now, the value will not be lost if you click on "dummy" button and if you modify the name and click on "submit" you will get the modified name. I hope this helps.
add a comment |
up vote
0
down vote
up vote
0
down vote
try below code.
.aspx
<script type="text/javascript">
$(document).ready(function () {
$("#txt_name").val("Cory");
});
</script>
<body>
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanelLossHistory" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<input type="text" runat="server" name="txt_name" id="txt_name" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />
<asp:Button runat="server" ID="Button2" Text="DummyPostback" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
string txtName = Request.Form["txt_name"];
}
There are two buttons, one for submitting and second one for dummy postback hit.
Now, the value will not be lost if you click on "dummy" button and if you modify the name and click on "submit" you will get the modified name. I hope this helps.
try below code.
.aspx
<script type="text/javascript">
$(document).ready(function () {
$("#txt_name").val("Cory");
});
</script>
<body>
<form id="form1" runat="server">
<asp:UpdatePanel ID="UpdatePanelLossHistory" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<input type="text" runat="server" name="txt_name" id="txt_name" />
<asp:Button runat="server" ID="Button1" Text="Submit" OnClick="Button1_Click" />
<asp:Button runat="server" ID="Button2" Text="DummyPostback" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
string txtName = Request.Form["txt_name"];
}
There are two buttons, one for submitting and second one for dummy postback hit.
Now, the value will not be lost if you click on "dummy" button and if you modify the name and click on "submit" you will get the modified name. I hope this helps.
answered Nov 20 at 10:32
A.M Codex
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386572%2fasp-textbox-value-assigned-in-client-side-not-appearing-in-postback%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if you want to keep your data after postback , you need to keep them somewhere on your page (hidden fields , json,...). and it dosnot cost you a lot
– Hamed
Nov 20 at 5:29
Try to use Input control and use as like "Request.Form["name"]" in backend.
– Jitendra Rangpariya
Nov 20 at 5:35
Thanks for your response sir, but will you please clarify it more
– Rohit_Chiki
Nov 20 at 5:40
Ok fine. let me explain as answer.
– Jitendra Rangpariya
Nov 20 at 5:41
yes please......
– Rohit_Chiki
Nov 20 at 5:44