[英]Convert Button Click to Page Load
我有一个 ASP 按钮单击方法,我想从用户单击按钮更改
<asp:Button id="createInvoice" runat="server" OnClick="InvoiceBtn_Click" Text="Create Invoice button" />
在Page_Load
上执行:
protected void Page_Load(object sender, EventArgs e)
{
AsyncMode = true;
if (!dictionary.ContainsKey("accessToken"))
{
if (Request.QueryString.Count > 0)
{
var response = new AuthorizeResponse(Request.QueryString.ToString());
if (response.State != null)
{
if (oauthClient.CSRFToken == response.State)
{
if (response.RealmId != null)
{
realmId = response.RealmId;
if (!dictionary.ContainsKey("realmId"))
{
dictionary.Add("realmId", realmId);
}
}
if (response.Code != null)
{
authCode = response.Code;
Session["authcodes"] = authCode;
output("Authorization code obtained.");
PageAsyncTask t = new PageAsyncTask(performCodeExchange);
Page.RegisterAsyncTask(t);
Page.ExecuteRegisteredAsyncTasks();
}
}
else
{
output("Invalid State");
dictionary.Clear();
}
}
}
}
else
{
oauth.Visible = true;
connected.Visible = true;
}
}
#region button click events
public async void InvoiceBtn_Click()
{
if (dictionary.ContainsKey("realmId") && dictionary.ContainsKey("accessToken"))
{
Action<ServiceContext> apiCallFucntion = new Action<ServiceContext>(CreateInvoiceCall);
await QBOApiCall(apiCallFucntion);
}
else
{
lblQBOCall.Visible = true;
lblQBOCall.Text = "Access token not found.";
}
}
我更改了方法中的最后一个 else 语句和最后一行,它可以工作。 我确定它需要重构,但它可以工作。
else
{
oauth.Visible = true;
connected.Visible = true;
InvoiceBtn_Click(createInvoice, EventArgs.Empty);
}
InvoiceBtn_Click(createInvoice, EventArgs.Empty);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.