Michael Tot Korsgaard
Michael Tot Korsgaard

Reputation: 4014

Request[] is null but have a value

I have this request. But when checking its value it is null. How can this be when I've set value="edit_show"?

@{
    bool edit_show = false;

    if (Request["btn"] == "edit_show")
    {
        edit_show = true;
    }
}

    <button type="submit" name="btn" id="edit_show" value="edit_show" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></button>

Upvotes: 0

Views: 67

Answers (1)

JotaBe
JotaBe

Reputation: 39014

button values have different behaviours depending on the browser. From w3schools HTML button tag:

Tips and Notes Note: If you use the element in an HTML form, different browsers may submit different values. Use to create buttons in an HTML form.

If you need to post an additional value with your button, create a <input type='hidden' .../> and its value will be posted. Or create your button using a <input type='submit' .../>

In your case, you can't use the second solution (the proposed in w3schools) because you have embedded hmtl inside your button, unless you change your desing.

Of course, the button must be inside the same form that the hidden files that you want to post.

Upvotes: 1

Related Questions