2

Iam using html control in mysite (idon't want to use asp controls).problem here i'am unable to get the data in label and textbox in codebehind c# he is my html controls

<form runat="server" class="sainex_form1">
    <input id="txtDateTime" runat="server" value="" type="text"  datetime="datetime" />
    <label id="lblJobCity" runat="server">
</form>
<p class="button-row">
    <input class="btn-submit" runat="server" type="image" name="image" id="Image4"   onclick="UpdateActivity()" />
</p>

in updateActivity() i'm sending values to c# using jquery AJAX

and im using this code in C#

for textbox:

string a=txtDateTime.Value;

for label:

string b=lblJobCity.InnerText;

from above to i'm getting empty value and i also tried

Request.Form["lblJobCity"].ToString();

but no result plz suggest me on this

9
  • Request.Form["lblJobCity"].ToString(); actually gave you no result? Not a null reference exception? Commented May 30, 2014 at 18:53
  • yes im getting null reference exception @Andrew Commented May 30, 2014 at 18:58
  • Do you have values in the controls? Commented May 30, 2014 at 19:01
  • I think we need to see your <form> tag. Oh, and by the way; You can't use Request.Form to access the information on the <label> at all. And finally; do you have ViewState disabled? Commented May 30, 2014 at 19:02
  • i'm unable to use <form> because not submitting the entire form.and can i get the values without using form tag? @Anderw Commented May 30, 2014 at 19:20

1 Answer 1

1

Do put some values in the controls: E.g.

<input id="txtDateTime" runat="server" value="2014-12-12" type="text" datetime="datetime"/>
<label id="lblJobCity" runat="server">Some Text goes here </label>

Then txtDateTime.Value and lblJobCity.InnerText will provide data server-side

UPDATE Here's complete form to make it work:

<form id="form1" runat="server">

   <input id="txtDateTime" runat="server" value="" type="text" datetime="datetime"  />
   <label id="lblJobCity" runat="server">Seattle</label>

   <input type="submit" id="submit" runat="server" onserverclick="submit_ServerClick" />
</form>

And then check the values in the event:

protected void submit_ServerClick(object sender, EventArgs e)
{
    string a = txtDateTime.Value;
    string b = lblJobCity.InnerText;
}
Sign up to request clarification or add additional context in comments.

5 Comments

then i'm getting the data i've given in html not the value i entered in input
Input should appear as well, but on submit. E.g. add <input type="submit" /> to those controls and check values upon clicking button (I've updated my answer to a small runnable sample)
Isn't the submit_ServerClick a control?
plz see my edited answer i'm using jquery AJAX to communicate with code behind
submit_ServerClick is an event handler for submit button. But @user1943217 heavily modified the question, there wasn't any mention of AJAX before. Or form construct. So I sense downvotes coming.

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.