How to make a button that just cleans up text boxes data? - asp.net

How can i make a button work such that it clears up all text boxes of pop up at a same time ...
Is there a single line of code which can perform the above function?
I tried this
protected void AddNext_Click(object sender, EventArgs e)
{
AccountNumber.Text = null;
AccountTitle.Text = null;
PinNumber.Text = null;
CreationDate.Text = null;
Balance.Text=null;
AccountTitle.Text = null;
}
But is there a better way to Get all text boxes blank ??

this works if you want ALL textboxes on your page to be cleared on the click of a button:
protected void Button1_Click(object sender, EventArgs e)
{
foreach (TextBox i in this.Page.Form.Controls.OfType<TextBox>().ToList())
{
i.Text = null;
}
}
i'd be careful with this tho, as it will clear every textbox that is located on your page. But apart from that, this does what you asked for.

Find the form it's in and call reset() function on it in JavaScript onclick of button.

Related

Validation in different Tabs of windows form using ErrorProviders

I am working on a windows Forms Application and trying to validate few textboxes using errorproviders but the problem is when I am clicking on a button present in Tab 1, all the textboxes even present on a different tabs gets validated. I want the validation to occur for textboxes present on the current tab and not on any control present on any other tab. How can I achieve this? Please help. Below is the code related to validation in the click event.
private void btnCreateUser_Click(object sender, EventArgs e)
{
if (this.ValidateChildren(ValidationConstraints.Enabled))
{
// Some Code here
}
}
Below is code used for validating and validated event for one textbox. I am using similar code for other textboxes as well present on other tabs.
private void txtFirstNm_Validating(object sender, CancelEventArgs e)
{
bool cancel = false;
if (txtFirstNm.Text.Trim().Length == 0)
{
cancel = true;
errorProvider1.SetError(txtFirstNm,"Please enter First Name");
}
else
{
cancel = false;
errorProvider1.SetError(txtFirstNm, "");
}
e.Cancel = cancel;
}
private void txtFirstNm_Validated(object sender, EventArgs e)
{
errorProvider1.SetError(txtFirstNm,"");
}
The Scenario that is given in my question can be handled by using below code. We can use the ValidationConstraint as Visible and this will make sure that Validation occurs on the Current visible Controls.
private void btnCreateUser_Click(object sender, EventArgs e)
{
if (this.ValidateChildren(ValidationConstraints.Visible))
{
// Some Code here
}
}

How to Display ASP Gridiew Empty Data Text after Clicking Search Button

Pls Help Me
The problem here is that i want the empty data template to be Display after the button search has been click but right now every time i open the page, it will show the empty data template before do any searching ....
if(!IsPostBack)
{
//put ur gridview connection here;
}
protected void Page_Load(object sender, EventArgs e)
{
grid1.DataSource = sqlboxfile;
DataBind();
grid2.Visible = false;
}

Select all items in listbox when updated via UpdatePanel

protected void Page_Load(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(this).IsInAsyncPostBack)
{
string id = ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID;
if (id == cboGroup.UniqueID)
{
foreach (ListItem i in lstTest.Items)
i.Selected = true;
}
}
}
This code runs when my cboGroup causes my UpdatePanel to refresh which has the lstTest in it and the data inside of it gets updated, but it does NOT select them all. How can I make it so when my UpdatePanel is finished refreshing all elements of the list box that it refreshed get selected?
[edit] I'm noticing now that at this point what's in the listbox is the previous values and not the new values I would need. So this seems to be before the listbox is filled with data (which is via a SqlDataSource) so it's probably overwriting this.
I was able to put my selection code in the list box's DataBound() event.
protected void lstTest_DataBound(object sender, EventArgs e)
{
SelectAllTest();
}

How to display gif while GridView Process ASP.NET

I have an application that displays various data in an ASP.NET GridView. The values ​​are displayed as a selection of combobox. When I select comobo box, the reload process is taking about 8 seconds. I would like to display a gif of load before starting the process and end it cancel the display image. I tried to use a thread for this, but it did not work very well. Could someone help me?
protected void Page_Load(object sender, EventArgs e)
{
//My Image
imageLoad.Visible = true;
Assembly myAsm = Assembly.Load("PainelBordo");
AssemblyName aName = myAsm.GetName();
Version version = aName.Version;
BusinessLogicLayer bll = new BusinessLogicLayer();
LoadDDLWRTG(CreateDataTableWRTGList());
LoadDataPBList();
TimerRefresh.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["TimerInterval"].ToString());
lblUpdateDate.Text = "Refresh " + bll.DateUpdateFormat(DateTime.Now);
// My image
imageLoad.Visible = false;
}
Combobox SelectedIndexChanged.
protected void ddlWRTGroup_SelectedIndexChanged(object sender, EventArgs e)
{
Page_Load(sender, e);
}
Drag and drop a Button(btnInvoke) and Label(lblText) control inside the UpdatePanel. Also add a <div id="divImage"> inside the UpdatePanel. This div will contain a .gif image that depicts progress and is initially set to invisible style="display:none". On the button click, perform a time consuming task. In our case, we have set a delay of 3 seconds by using Thread.Sleep(3000)
C#
protected void btnInvoke_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
lblText.Text = "Processing completed";
}
Took from here

Asp.net page - user control communication

I have a page Product.aspx,there I have a user control ProductDisplay.ascx which has been created by drag and drop.
Now when a button is clicked in ProductDisplay.ascx,I want a logging function to be called which is in Product.aspx.
To achieve this I have used delegates
on ProductDisplay.ascx
public delegate void LogUserActivity(ProductService objService);
public event LogUserActivity ActivityLog;
on Product.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ProductDisp.ActivityLog += new User_UserControl_ProductDisplayBox.LogUserActivity(LogProduct);
}
}
Now button click event of ProductDisplay.ascx
protected void imgBtnBuyNow_Click(object sender, ImageClickEventArgs e)
{
if (ActivityLog != null)
{
ActivityLog(Product);
}
Response.Redirect("~/User/ShoppingCart.aspx");
}
My problem is that whenever i click this button ActivityLog is null.Why is it null?
My idea is that once i click this button,page posts back and its previous state is lost.
Please help me out with a reason and solution.
Secondly,I want to do away with null checking
**if (ActivityLog != null)**
{
ActivityLog(Product);
}
I saw some code which instantiates a delegate with a default value the moment it is declared,but i was not able to find it.Please help.
I have found solution to first problem
if (!IsPostBack)
{
ProductDisp.ActivityLog += new User_UserControl_ProductDisplayBox.LogUserActivity(LogProduct);
}
This was causing the issue.Move this line
ProductDisp.ActivityLog += new User_UserControl_ProductDisplayBox.LogUserActivity(LogProduct);
out of if (!IsPostBack)

Resources