0

So I have a Web Forms asp control:

<asp:DropDownList runat="server" ID="ExistingTemplate" ClientIDMode="Static" />

On the backend code, it gets populated through this:

public override void DataBind()
    {
        base.DataBind();

        var selectList = Chatham.Web.Models.Indications.DropDownData.AllEditableTemplates();
        ExistingTemplate.DataSource = selectList.Items;
        ExistingTemplate.DataTextField = selectList.DataTextField;
        ExistingTemplate.DataValueField = selectList.DataValueField;
        ExistingTemplate.DataBind();


        SetTabVisibility();
    }

Now, I want to refactor the AllEditableTemplates method to take a parameter. This parameter is only accessible through the client side Javascript code, on the master page front end.

How can I pass a parameter to this method that I get from Javascript on the page?

2 Answers 2

1

You could use JavaScript to store it in a hidden form field. Then it would be easy to retrieve it from the server-side using the HttpRequest.Form property.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm, that's a thought. Let me give that a shot.
0

Expose it as a web method and have javascript call it, instead of it trying to get the value from javascript. http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx

Using a hidden field has a problem - normally, data bind is called right away somewhere, which means the initial request to the web server didn't have the form field set yet and it will be empty. You would need a second request in order for it to populate so that your form request had it. Calling the web method from the client instead solves this problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.