2013-02-28 135 views
1

我有註冊表單,我正在接收用戶輸入並將信息傳遞到付款網站。付款網站有幾個隱藏字段,因此它可以將每個單獨的用戶區分爲唯一而不是依賴用戶提供的唯一名稱。這就是「unique_id」字段,我想要一個隨機數字作爲參數。我怎麼做這項工作,所以每次用戶點擊這個代碼所附的按鈕時,它都會執行RNG並將該號碼傳遞給外部支付網站?RNG隱藏字段參數

...

protected void submitButton_Click(object sender, EventArgs e) 
    { 
Random randnum = new Random(); 
int num = randnum.Next(); 
     { 
      NameValueCollection PostFields = new NameValueCollection(); 
      PostFields.Add("LMID", "345573"); 
      PostFields.Add("unique_id", RANDOM NUMBER HEEDS TO GO HERE); 
      PostFields.Add("sTotal", "150.00"); 
      PostFields.Add("webTitle", "Conference"); 
      PostFields.Add("Trans_Desc", "Conference Registration"); 
      PostFields.Add("contact_info", "Contact admin"); 
      PostFields.Add("BILL_CUSTOMER_FIRSTNAME", labelFirstName.Text); 
      PostFields.Add("BILL_CUSTOMER_LASTNAME", labelLastName.Text); 
      PostFields.Add("BILL_ADDRESS1", labelAddress.Text); 
      PostFields.Add("BILL_CITY", labelCity.Text); 
      PostFields.Add("BILL_STATE", labelState.Text); 
      PostFields.Add("BILL_ZIP", labelZip.Text); 
      PostFields.Add("BILL_CUSTOMER_PHONE", labelTelephone.Text); 
      PostFields.Add("BILL_CUSTOMER_EMAIL", labelEmail.Text); 
      RedirectAndPOST(this.Page, "payment website url", PostFields); 
     } 

...

+2

您是否嘗試過'num.ToString()'? – StarPilot 2013-02-28 22:08:08

+0

是的,它給了我一個超負荷的錯誤 – Michael 2013-02-28 22:12:46

+0

發佈代碼給你的重載錯誤,以及你得到的確切的錯誤信息和異常類型。 – 2013-02-28 22:18:05

回答

1

這對我工作得很好:

Random random = new Random(); int num = random.Next(); 

    NameValueCollection PostFields = new NameValueCollection(); 
    PostFields.Add("LMID", "093204"); 
    PostFields.Add("unique_id", num.ToString()); 
+0

感謝StarPilot說過的話,並且在我調整了一些低於我發佈的代碼之後,它工作正常。 – Michael 2013-02-28 22:23:21