Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP button not firing event on intial Click.

Posted on 2004-08-04
3
Medium Priority
?
408 Views
Last Modified: 2010-04-06
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" />

0
Comment
Question by:icompass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:viola123
ID: 11722717
i suggest you using a boolean variable to control this process. the code to achieve that could be:

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

        }
}
0
 
LVL 6

Expert Comment

by:viola123
ID: 11723331
sorry, i misunderstand you just now. the solutions should be:

1. for your static submit button:
<form id="form1" method="get" action="thispage.aspx?status=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"].ToString();
}

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
        }
}
0
 
LVL 1

Accepted Solution

by:
MrBic earned 2000 total points
ID: 11727426
Viola123 hit it, but we gota take it a step further.

Seeing your buttons are dynamically created, we need a query string for them, so your code behind knows which itteration of the repeater you're using.

The repeater will name controls like :  RepeaterName__ctl00_IDofControl

so Grab the ctl00 or ctl312 , whatever it may be, and throw that into a QS. Read that in on the page load, and go from there.

You could use JS to change the QS of the form, but .NET has had issues with that in the past with a server side form tag.


Hope this helps!

/Bic
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question