开发者

How can i include the clicked element's id in an ajax call?

开发者 https://www.devze.com 2022-12-17 07:38 出处:网络
I\'m trying to bring over the IDs of the input elements \"submit\" and \"skip\" and do some logic based on which button was pushed.It doesn\'t appear to be coming over in the Request object.How can I

I'm trying to bring over the IDs of the input elements "submit" and "skip" and do some logic based on which button was pushed. It doesn't appear to be coming over in the Request object. How can I do this???

<div id="modal">
    <% using (Ajax.BeginForm("Promo", new AjaxOptions { UpdateTargetId = "modal" }))
       { %>
    <div id="modal_inner">       
        <div style="clear: both;">
            <%= Html.TextBox("Data1")%>
            <input name="submitBtn" id="submitBtn" type="image" src="button_submit.gif" width="74" alt="Submit" />
            <input name="skipBtn" id="skipBtn" type="image" src="button_skip.gif" alt="Skip" />            
            <br />
        </div>
    </div>
    <% } %>
</div>

public JavaScriptResult Promo(string Data1)
        {
            string submitBtn = Request.Params["submitBtn"];
            string skipBtn = Request.Params["skipBtn"];
            if (skipBtn != null)
            {
                Session["Data1"] = "Default";
                return JavaScript("window.top.location.href ='" + Url.Action("Index", "Lead") + "';");
            }
            if (submitBtn != null && IsValidCode(Data1))
            {
                Sessi开发者_StackOverflow社区on["Data1"] = Data1;
                return JavaScript("window.top.location.href ='" + Url.Action("Index", "Lead") + "';");
            }
            Session["Data1"] = "Default";
            return JavaScript("$('TB_window').dispose(); TB_show('', '#TB_inline?&width=344&height=294&inlineId=modal', '::::');");
        }


I had the same problem using jQuery, it would not serialize the name of the form element I clicked. I had to seperately detect the onclick of the submit button, get the name of the button, and add it to the serialized query to be sent back with the Ajax call.

Sorry I do not know which Ajax framework you are using here so I cannot help with the actual code.

0

精彩评论

暂无评论...
验证码 换一张
取 消