icompass
asked on
ASP button not firing event on intial Click.
I have a page that has X amount of ASP buttons on it. These buttons are dynamically generated. I also have 1 statick Button on the page, near the bottom (submit).
I have an issue with the dynamic buttons. The buttons's purpose is to switch items from one list box to another, by traversing through the controls on the page.
When you select the items you want moved, and click a button, the page will postback to itself, but the SENDER will be the page, and not the button.
The page refreshes.
Now, if you try and use the buttons to switch the items, it works perfectly, as it should.
This will also happen if you use the static submit button... but it submits right away, and the buttons to switch items works after that too.
So... my question is, is there a way for these buttons to call the event on the first click? Is there a hack around it?
Here is the declaration of my buttons:
<asp:button cssclass="BoxType42" id="btnDisAllow" Text="DisAllow" onclick="SwitchItem" runat="server" />
</td><asp:button cssclass="BoxType42" id="btnAllow" Text="Allow" onclick="SwitchItem" runat="server" />
I have an issue with the dynamic buttons. The buttons's purpose is to switch items from one list box to another, by traversing through the controls on the page.
When you select the items you want moved, and click a button, the page will postback to itself, but the SENDER will be the page, and not the button.
The page refreshes.
Now, if you try and use the buttons to switch the items, it works perfectly, as it should.
This will also happen if you use the static submit button... but it submits right away, and the buttons to switch items works after that too.
So... my question is, is there a way for these buttons to call the event on the first click? Is there a hack around it?
Here is the declaration of my buttons:
<asp:button cssclass="BoxType42" id="btnDisAllow" Text="DisAllow" onclick="SwitchItem" runat="server" />
</td><asp:button cssclass="BoxType42" id="btnAllow" Text="Allow" onclick="SwitchItem" runat="server" />
sorry, i misunderstand you just now. the solutions should be:
1. for your static submit button:
<form id="form1" method="get" action="thispage.aspx?stat us=1">
<input type="submit" value="Submit form">
</form>
2. in the code behind of your aspx page,eg. thispage.aspx.cs:
protected string status="0";
private void Page_load(........)
{
status = Request.Params["status"].T oString();
}
private void SwitchItem()
{
if (status != "1")
{
................
................
................
................// this is your original code
status = "0"; // set it as 0, so you code won't be processed next time
}
}
1. for your static submit button:
<form id="form1" method="get" action="thispage.aspx?stat
<input type="submit" value="Submit form">
</form>
2. in the code behind of your aspx page,eg. thispage.aspx.cs:
protected string status="0";
private void Page_load(........)
{
status = Request.Params["status"].T
}
private void SwitchItem()
{
if (status != "1")
{
................
................
................
................// this is your original code
status = "0"; // set it as 0, so you code won't be processed next time
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
protected bool status = true;
private void Page_load(........)
{
.....................
}
private void SwitchItem()
{
if (status == true)
{
................
................
................
................// this is your original code
status = false; // set it as false, so you code won't be processed next time
}
}