I just want to ask if there is an opportunity to change:

HTML / ASP.NET: <input type = "hidden" name = "reference" value = "ABC" / ">

I just want to ask if there is an opportunity to change:

<input type="hidden" name="reference" value="ABC"/> 

in it:

 <input type="hidden" name="reference" value="any values I want"/> 

where I can set any values ​​beyond .cs / C # - making it dynamically. The payment gateway used requires, and I can’t find a way to enable the ASP.NET control (?) And I need your suggestions / comments on this. Thanks.

PS. <asp:HiddenField ID="reference" runat="server" Value="ABC" /> does not work, because the payment gateway specifically needs the "name" property.

+4
source share
3 answers

I know this is an old post, but for those who want to solve this problem now. If you add runat="server" to the input, the name will be changed (for example, MainContentArea_ctl00_ctl01_ctl01_amount ). ClientIdMode="Static" will only help ID. To get around this:

On your html page use Literal:

  <asp:Literal runat="server" ID="litInputAmount"></asp:Literal> 

In the code behind the file, assign a line to the Text attribute in Literal. This line should be html, as you would like. The correct value can also be added for the value field:

  litInputAmount.Text = String.Concat("<input id='inputAmount' type='hidden' name='amount' value='", Price.ToString(), "'>"); 

Then it will be compiled as:

  <input id="inputAmount" type="hidden" value="224.4" name="amount"> 

This will provide information to the payment gateway with the correct name, but your value can be controlled dynamically. Repeat for any other values ​​that need to be added before sending.

+5
source

You can simply put runat="server" in the control to access it from your code:

 <input type="hidden" name="reference" id="reference" runat="server" /> 

Then in your code behind:

 void Page_Load(object sender, EventArgs e) { // ... reference.Attriutes["value"] = "any values I want"; // ... } 

Please note that in this case the id attribute is required because when you have runat="server" , the id attribute is used to indicate the name of the generated variable.

+3
source

//<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> protected string GetVariableValue(string AspxPage, string inputTagName) { ra migirad string RegPattern = string.Format("(?<=({0}\".value.\")).*(?=\"./>)", inputTagName); Regex regex = new Regex(RegPattern, RegexOptions.IgnoreCase); Match match = regex.Match(AspxPage); if (string.IsNullOrEmpty(match.Value)) { RegPattern = string.Format("<input[^>]*{0}[^>]*value=\"([^\"]*)\"", inputTagName); regex = new Regex(RegPattern, RegexOptions.IgnoreCase); match = regex.Match(AspxPage); return match.Groups[1].Value; } return match.Value; }

0
source

Source: https://habr.com/ru/post/1314393/


All Articles