Friends i am stuck with a strange issue and i need your suggests to fix it.
In my Master page I am using a Search box with a button, it works fine in all pages except the "Request Quote page" which have a form for users to fill.
If a person is on the Request Quote page and want to search using the searchbox in head section, it do not take the user to the search result page, instead it triggers the form validations of the "RequestQuote Form"
Here are my codes;
Search Box from MasterPage Head Section
<asp:TextBox ID="SearchBox" runat="server" CssClass="search_textbox" ></asp:TextBox>
<asp:ImageButton ID="SearchButton" runat="server" onclick="SearchButton_Click" />
protected void ISearchButton_Click(object sender, ImageClickEventArgs e)
{ Response.Redirect("Search-commercial.aspx?Zip=" + SearchBox.Text); }
Some Codes from Request Quote Page
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:ImageButton ID="QuoteButton" runat="server" onclick="QuoteButton_Click" />
protected void IQuoteButton_Click(object sender, ImageClickEventArgs e)
{ SqlDataSource3.Insert();
Response.Redirect("InstallerThanks.aspx");
}
Friends any idea where i made the mistake?
Instead of disabling all validators you should use different ValidationGroups.
Related
since I am new to ASP .NET I wonder whether this is normal behavior or something strange. I am trying to convert C# WinForms app to web app and it is behaving not as I expected.
In desktop app I get data after user press enter on textbox. Data are loaded I can modify it and then, when I am done changing data I can press one of two buttons and data are saved to database or form is cleared. Something like this.
private int idOrder;
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if(load_data)
{
label1.Text = "some loaded data";
...
else{ MessageBox.Show("Something went wrong. No data loaded");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//save to database;
}
But When I try to do the same in ASP.NET Web form, whenever I press enter on textbox all controls are fired (as it is written in source code line after line) when page is refreshed. Could you please advice we what should I do to replicate same behavior as in winforms e.g. user input - enter - load data - modify - press button when I want. Thank you.
//Is the view state thing I am looking for?
Here is a snippet to get you started. Keep in mind that posting a HTML form when pressing enter is default behavior for websites. So the first thing is preventing that by wrapping the TextBox and Submit Button with a Panel with a DefaultButton assigned to it. Now when the enter is pressed in TextBox1, it will post the form as dummyButton
Next we add an OnTextChanged event to TextBox1 and set AutoPostBack to true. This will fire when the focus of TextBox1 is lost. You could remove this and just use the enter with dummyButton.
The dummyButton is added to ensure the form will PostBack when enter is pressed in TextBox1 to get the desired behaviour.
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:LinkButton ID="dummyButton" runat="server" OnClick="TextBox1_TextChanged"></asp:LinkButton>
</asp:Panel>
And then in code behind.
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//load from database
Label1.Text = TextBox1.Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
//save to database
Label1.Text = "Data saved!";
TextBox1.Text = "";
}
You can also prevent PostBack with enter like this. The JavaScript will block all enters. Depending on your page design you could set this in the <body> tag for example.
<div onkeydown="return (event.keyCode!=13);">
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
</div>
Im trying to create a search button on my website on my homepage which is an aspx page but when I click search all it does is refresh the page instead of preforming the query, any help would be appreciated
heres the code for my index.aspx and the code for my index.aspx.cs page
<asp:TextBox ID="searchtitle" runat="server"></asp:TextBox>
<asp:Button ID="searchitems" runat="server" Text="Search" />
protected void searchitems_Click(object sender, EventArgs e)
{
String stext = searchtitle.Text;
Response.Redirect("search.aspx?searchquery=" + stext);
}
The button is not working because you didnt call the event on the button
<asp:Button ID="searchitems" runat="server" OnClick="searchitems_Click" Text="Search" />
add OnClick attribute with name of the event you want to call and in the given code the event you want to call is searchitems_Click.
definitely when you will click the searchitems page will reload because function for that click is defined on server side.. what you have to do is on the pageload look for the QueryString and get the value of ["searchquery"] then manipulate it as you want..
if you want to not refresh the page use Ajax then...
I want to display a particular div on the click of a button
My asp code is as follows
<asp:Button ID="Button1" class="btn" runat="server" OnClick="Submit" />
<div runat="server" id="signup" Visible="false">Some Content </div>
Now in the CodeBehind i have written the following code
protected void Submit(object sender, EventArgs e)
{
Button1.Visible = false;
signup.Visible = true;
}
But every time i get the error as
the name signup does't exist in the current context
i am not able to figure out the problem in the code..
You probably have wrong html for the div, you can also use style="visible:none" instead of Visible="false"
Change
visible:"false"
To
Visible="false"
This has to be done through JavaScript, I believe in the onClientClick attribute of the button. I'm currently searching for the code to jog my own
I have a user control that allows the user to add/edit a worker. When the user clicks the 'Add Worker' button the user control appears in a DevExpress Popup. All of the following button are in an update panel to prevent Postbacks.
When I edit a user (pencil) everything works fine. To edit a user I enter a last name, click search (magnifying glass) and then click edit (pencil). It's only when I load the page and click add the save/cancel buttons do not work.
I add the control in asp.net
<dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server" SupportsDisabledAttribute="True">
<uc:WorkerAddEdit ID="wae" runat="server" OnOnWAECancelEvent="wae_OnWAECancelEvent" OnOnWAESaveEvent="wae_OnWAESaveEvent" />
</dx:PopupControlContentControl>
Here is the C# code behind the edit (the one that works correctly. The pencil)
protected void btnEditWorker_Click(object sender, EventArgs e)
{
SetupSessions();
wae.WorkerEdit = loadedWorker;
pucAddEditWorker.HeaderText = "Edit Worker";
pucAddEditWorker.ShowOnPageLoad = true;
}
Here is the C# code behind for the add (the round + that doesn't work)
protected void btnAddWorker_Click(object sender, EventArgs e)
{
wae.WorkerEdit = null;
pucAddEditWorker.HeaderText = "Add Worker";
pucAddEditWorker.ShowOnPageLoad = true;
}
Here is the asp.net section of the save and cancel button. This shows both onClick calls
<td><dx:ASPxButton ID="btnSave" runat="server" Text="Save" Theme="MetropolisBlue"
Width="50px" Height="20px" style="float:right;" onclick="btnSave_Click" /></td>
<td><dx:ASPxButton ID="btnCancel" runat="server" Text="Cancel"
Theme="MetropolisBlue" Width="50px" Height="20px" style="float:right;"
onclick="btnCancel_Click" /></td>
Here is the events in the code behind
protected void btnCancel_Click(object sender, EventArgs e)
{
//Do Work Here
}
protected void btnSave_Click(object sender, EventArgs e)
{
// Do Work Here
}
If I put a break point on either the save or cancel click event nothing ever happens. I've been googling for a while now with no luck.
Thanks in advance.
In Design mode of the form, have you tried clicking the control once, and check it on Properties (Events) window? Maybe the Click event does not have any method selected.
Select the btnSave_Click method in the Click label.
I figured out what the problem was. I am using a textbox from DevExpress. Further up in my code I had the textbox as follows:
<dx:ASPxTextBox ID="txtPhoneNumber" runat="server" Width="100px" Theme="MetropolisBlue" >
<MaskSettings Mask="(999) 000-0000" IncludeLiterals="None" />
<ValidationSettings Display="None">
</ValidationSettings>
</dx:ASPxTextBox>
Because I had the 0's in the mask it was trying to validate whatever was in the text box. Because I turned off the validation settings (ValidationSettings Display="None") I never saw the error but it was still validating. I made a change to this:
<dx:ASPxTextBox ID="txtPhoneNumber" runat="server" Width="100px" Theme="MetropolisBlue">
<MaskSettings Mask="(999) 999-9999" IncludeLiterals="None" />
<ValidationSettings Display="None">
</ValidationSettings>
</dx:ASPxTextBox>
and everything worked fine. I just started using DevExpress and it shows! Thanks to everyone for the help!
I am new at AJAX When i enter the web page it gives an error which is
``(c:\Users\Acer\Desktop\RSS_proje\RSS_proje\WebApplication2-5.2\ShareRss.aspx
var lblMsg = $get('<%=lblMessage.ClientID%>');){"Control 'ScriptManager1' of type 'ScriptManager' must be placed inside a form tag with runat=server."}
javascript side
HTML code[code:html]<asp:ScriptManager ID="ScriptManager1" runat="server">
function onCancel() {
var lblMsg = $get('<%=lblMessage.ClientID%>');
lblMsg.innerHTML = "You clicked the <b>Cancel</b> button of AJAX confirm.";
}
also, button side
<asp:Button ID="Button1" runat="server" Text="Share RSS" BackColor="#FF6600"
BorderColor="#FF9933" BorderStyle="Solid" Font-Bold="True" ForeColor="White"
Width="78px" onclick="Button1_Click" />
<ajaxToolkit:ConfirmButtonExtender ID="cbe" runat="server"
TargetControlID="Button1"
ConfirmText="Are you sure you want to share this?"
OnClientCancel="CancelClick" />
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />
C# SIDE
protected void Button1_Click(object sender, EventArgs e)
{
lblMessage.Text = "You clicked the <b>OK</b> button of AJAX confirm";
}
If the ScriptManager tag is formatted exactly as you have it posted then make sure you're providing the appropriate closing tag for it. If you already are could you post a bit more of your markup so we can gat a better picture of how your Dom is structured