Displaying a div on a button click in asp.net - c#

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

Related

how to include a User Control in a Web Forms Page from code behind?

im trying to make a user control to popup when a button is clicked! now i dont want to hide the user control and then show it when the button is clicked,
im NOT trying to do this:
test1.aspx
<uc1:PopUp ID="PopUp1" runat="server" Visible="false" />
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
test1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
if(PopUp1.Visible==false)
PopUp1.Visible = true;
else
PopUp1.Visible = false;
}
i want the page loads without it and if the button is clicked it fires! is it possible?
btw, im open to any other suggestion other than using user control
thank you in advance

User Control Buttons Not Firing

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!

How to save tinymce using asp button

I'm using asp.net and c# to build a website that can upload,edit,save the file. I have use tinymce as the texteditor but the problem is the I dint know how to configure the save plugins in tinymce..I have add asp button to use as save button but how to configure it to save into file .html?
javascript to replace tiny with texeditor:
$('#<%=btnsave.ClientID%>').show() //save button
tinymce.init({selector: "textarea"}); //replace texteditor
this is markup code:
<textarea name="textarea" cols="100" rows="5" style="visibility: hidden;">
</textarea>
<br /><asp:Button Text="Save" runat="server" ID="btnsave" style="display:none;" onclick="btnsave_Click" />
This in code behind
protected void btnsave_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~/WordExcelPPointToHtml/test.html");
File.WriteAllText(path,HtmlTextArea); //this line have error!!
}
Can anyone help me on this ?. Thanks in advance. Eagerly waiting for answers.
You need to replace the html control with an ASP.NET web control, and they you will be able to access the value programmatically in the code behind.
E.g.
<asp:TextBox ID="txt" Name="textarea" Columns="100" Rows="5" TextMode="MultiLine" runat="Server"></asp:TextBox>
And in the code behind:
protected void btnsave_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~/WordExcelPPointToHtml/test.html");
File.WriteAllText(path, txt.Text);
}
You should also consider some error handling in btnSave_Click

Submit button conflicts with to different functions

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.

How close Html window when click asp.net button?

I have asp.net button "OK" in html popup window. I after my logic done how close that popup window it self?
<asp:Button Id="btnOK" runat="server" AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>" Width="70px" Text="<%$Resources:wss,
multipages_okbutton_text%>" OnClick="btnOK_Click" />
<asp:Button ID="btnOK" runat="server" OnClientClick="window.close(); return false;" Text="Close" />
All correct but there is another way if you want close the window in your code:
Suppose that the button ID is "ContineButton" and the click event handler name is "ContineButton_Click"
protected void ContineButton_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
If there is a chance that your server side code may fail, and you need to keep the popup open to correct errors, the OnClientClick trick won't help. I do this with a PlaceHolder and a small script:
<asp:PlaceHolder id="close_script" runat="server">
<script>window.close();</script>
</asp:PlaceHolder>
Then, in the button handler, set the Visible property of the PlaceHolder to close the popup (or leave it open:
protected void btnOK_Click(Object sender, EventArgs e) {
bool success = processPage();
close_script.Visible = success;
}
That requires some javascript. Change your button markup to this:
<asp:Button Id="btnOK" runat="server" AccessKey="<%$Resources:
wss,multipages_okbutton_accesskey%>" Width="70px" Text="<%$Resources:wss,
multipages_okbutton_text%>" OnClick="btnOK_Click" OnClientClick="javascript:window.close(); return false;" />
There are other things to consider here - an accessible site will work without JavaScript including opening and closing a popup window. It will be dumbed down, but still function. Take a look at this article:
http://accessify.com/features/tutorials/the-perfect-popup/

Categories

Resources