开发者

Can I retrieve the value of a standard input in ASP.NET?

I've created a custom server control in ASP.NET to render a standard checkbox and a hidden field like this:

public class CheckAllBox : WebControl
{

    private string checkboxClientID;

    protected override void OnInit(EventArgs e)
    {
        checkboxClientID = String.Format("{0}{1}chbCheckAll", base.ClientID, base.ClientIDSeparator); 
        base.OnInit(e);
    }

   protected override void Render(HtmlTextWriter writer)
    {
        //Render checkbox
        writer.AddAttribute(HtmlTextWriterAttribute.Id, checkboxClientID);
        writer.AddAttribute(HtmlTextWriterAttribute.Name, checkboxClientID);
        writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
        writer.AddAttribute(HtmlTextWriterAttribute.Value,开发者_开发问答 Values);
        writer.RenderBeginTag(HtmlTextWriterTag.Input);
        writer.RenderEndTag();

        //Render hidden field
        writer.AddAttribute(HtmlTextWriterAttribute.Id, String.Format("{0}{1}hdnExcludeValues", base.ClientID, base.ClientIDSeparator));
        writer.AddAttribute(HtmlTextWriterAttribute.Name, String.Format("{0}{1}hdnExcludeValues", base.ClientID, base.ClientIDSeparator));
        writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
        writer.AddAttribute(HtmlTextWriterAttribute.Value, ExcludeValues.ToString());
        writer.RenderBeginTag(HtmlTextWriterTag.Input);
        writer.RenderEndTag();
    }
}

Now I want to retrieve the value of the hidden field and the checkbox when it is posted back - is it possible with the standard html I have rendered?

I've already written jQuery that works with this markup but it does require a standard html checkbox with a value - not the kind of checkbox rendered by ASP.NET.

If it is not possible to retrieve the value from standard html inputs, do I need to rewrite this as a composite control, or is there another trick?


The Form property of the Request object contains the values of all form elements for the current request.

string key = ...; // "name" attribute of the form element
string val = Request.Form[key];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜