Link to home
Create AccountLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Clear __EVENTARGUMENT?

Is there a way to CLEAR __EVENTARGUMENT or set it to null or to some other value in the C# code behind.

I have a dynamic control with buttons inside of it.

I have the Button onclick set to run a Javascript function where it sets the __EVENTARGUMENT.

But it seems to be firing multiple times, even though I am only clicking the button once.
Avatar of Amaku
Amaku

Try setting it to null in your code behind.
Request["__EVENTARGUMENT"]=null;
Avatar of Tom Knowlton

ASKER

Cannot do that.

Request["__EVENTARGUMENT"]

is read-only.


It is javascript that is populating the event argument.


What I don't understand is why it is firing TWICE.
ASKER CERTIFIED SOLUTION
Avatar of Bane83
Bane83
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
First things first...I'm in C#.   :)

The event is being wired thus in the Page_Load for the custom button control:

protected void Page_Load( object sender, EventArgs e )
{
      Button1.Attributes.Clear();
      this.Button1.Attributes.Add("onclick","RespondToNewRowClick(this)");      
}


RespondToNewRowClick(this is a javascript function that looks like this:


<script type="text/javascript">
        function RespondToNewRowClick(current)
        {            
      __doPostBack(current.value,'NEWROWBUTTONCLICK');              
        }
</script>


When the button is clicked, on the server side code I respond to the message:


protected void Page_Load( object sender, EventArgs e )
{
      string tempArgument = Request.Params.Get("__EVENTARGUMENT");

      if (tempArgument == "NEWROWBUTTONCLICK")
      {                  
            AddToColl();
            TESTCOLLECTION1.AddControlCollection((List<Control>)Cache["ctrls"]);
      }

      if (!Page.IsPostBack)
      {
            Cache.Remove("ctrls");
            AddToColl();
            TESTCOLLECTION1.AddControlCollection((List<Control>)Cache["ctrls"]);
      }
            
}




I hope this helps you help me some.  :)
Huh, that's odd.

Could you try adding an alert(current.id); statement into the RespondToNewRowClick event to see if the javascript is also being called more than once?

Please make note of the id's it returns, just in case.