0

Is it possible to get the value of the html input field (expiration) in C# after the user clicks outside of the field? And set the value from database to the html input field on page load or on refresh. Here is my code:

<ext:Panel runat="server" Border="false">
     <Content>
            <label for="expiration"> Unknown date 2 </label>
            <input id="expiration" type="text" placeholder="DD(uu)/MM(uu)/YY(uu)" class="masked" title="title" runat="server" 
                                    pattern="^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$|(uu\/([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])\/[0-9]{1,4})|(uu\/uu\/[0-9]{1,4})|(uu\/uu\/uu)" 
                                    data-valid-example="01/05/18"> 
     </Content>
</ext:Panel>
2
  • As per @Alander 's answer, you need to add a name attribute to the input for it to get posted to the codebehind. Commented Jan 16, 2018 at 13:33
  • 1
    A better data-valid-example would be "31/05/18". Commented Jan 16, 2018 at 13:34

1 Answer 1

3

It should normally be done with Request.Form["elementName"].

In this case, Request.Form["expiration"] to access its value, change your input to use name instead of id <input name="expiration" ... /> for it to work

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

2 Comments

ok but I want to get the value after the user clicks out of the field. is that possible? and also get the value from db on page load and store it in the input field
is there a reason why you must use input? a textbox with autopostback can be easier.. a RegularExpressionValidator can be used with the textbox to validate the input as well

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.