views:

41

answers:

2

I gave a button an attribute called notetype.

 <asp:ImageButton ID="bttnSave" notetype="none" runat="server" ImageUrl="~/images/bttnSave.gif" onclick="bttnSave_Click" />

I have a function from a different button's click that sets that variable to some type.

function addnotes(Type,IncId,Acc,Wit,Claim,Inj,Prop,Media) {
    var bttnopenmodal = $get('<%=bttnopenmodal.ClientID %>');
    var bttnSave = $get('<%=bttnSave.ClientID %>');

    if (Type == 'Inc') {
        bttnSave.notetype = 'Inc';

    }

    bttnopenmodal.click();
    return false;
}

However in the C# code of the button:

protected void bttnSave_Click(object sender, ImageClickEventArgs e)
{
    Response.Redirect(bttnSave.Attributes["notetype"]);
}

the value of the save button's notetype is still 'none' even though i change it in javascript. I even alerted to make sure it changed the notetype and it did. I tried to update the button with an updatepanel to no avail. How can i correctly change that notetype?

+1  A: 

Your code behind will only pick up client side changes to data that can be posted. The data in a custom attribute doesn't get send back to the server on post back, so it will only know (by way of the view state) what value the attribute had when the page was rendered.

James Conigliaro
That makes since. Except for the fact that I can change the value of a hidden field and it works.
Eric
just didn't want to have to use hidden fields.
Eric
+1  A: 

Only the value attribute of a form control element is sent with the form post (and for <input type="image" /> nothing is sent at all). You can't expect the browser to know to send "notetype=none" in the post body just because you specified it as an attribute. That's what <input type="hidden" name="notetype" value="none" /> would be used for.

Viewstate makes you forget all this, until the point you try to change it in the client and the whole thing blows up.

Roatin Marth