0

Inherited an asp.net 3.5 C# site. Main page has a control in it that has a datagrid-if the user fails to put a file name and hits 'update', it's wrong-they have to supply a file name. They also have some custom business logic that I nicely have in the code behind. Any of these could mean the user needs to see an error at which point I cancel out of the SqlDataSource update, thus, reverting the grid back to its original value, fine...however, if I put an error message up in a text box(already did that), now, the user is staring at an error msg...I'd rather pop up a warning / error, and then it's all fixed.

SO.....I have the error in a hiddenfield...now, how can I force a click of a hidden button so I can alert the client?

2 Answers 2

1

The following is the code which validates the user input at code behind, and prompt a message if invalid.

// ASPX page
<asp:TextBox runat="server" ID="FileNameTextBox"></asp:TextBox>
<asp:Button runat="server" ID="SubmitButton" Text="Submit" OnClick="SubmitButton_Click" />

// Code behind
protected void SubmitButton_Click(object sender, EventArgs e)
{
    if (string.IsNullOrEmpty(FileNameTextBox.Text))
    {
        string script = string.Format("alert('File name is required.')");

        ScriptManager.RegisterStartupScript(Page, typeof(Page), "Validation" + UniqueID, script, true);
    }
}

enter image description here

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

Comments

0

How to trigger it from code behind: see here

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.