I'm new to asp.net and C#. Right now, I'm creating a small webpage with panels etc.
Situation:
I got a Panel (let's say Panel1). And an Imagebutton (Button1).
I can Show the Panel (onclick event) in aspx with visible = true.
Problem:
How do I close the Panel using the same button? I dont want to use Javascipt or jquery or anything else that is Client site.
Is there a simple solution for that?
Forgive my ignorance if this isn't available in ASP.NET but could you not do something like
Button1_ServerClick(object sender, EventArgs e)
{
Panel1.Visible = !Panel1.Visible; //toggles visibility
}
Related
I would like some help with code so my panels get brought to front when I click a button.
I have tried
private void button22_Click(object sender, EventArgs e)
{
panel4.BringToFront();
}
but that didn't seem to work for me.
Does anyone know what I'm doing wrong or how I could get this working?
I am in c# winforms.
That should work fine. You code says panel4 so I assume you have multiple panels.
If you have placed panel3 on panel4, then BringToFront() will bring both forward and may look like there is no change. Make sure both panels have the form as their parent. You can do this by cut and paste, or making sure that you click the form canvas (not an existing panel) when you add the other panels.
The same for buttons, textboxes etc, if you draw them on to a panel, they will stay as is on that panel when you bring them forwards.
Using VS2013, C#, .Net and Winforms how can I make a regular Button look "pressed"? Imagine this button is an on/off switch. ToolStripButton has the Checked property, but the regular Button does not.
Are you really forced to use a button or does it just have to look like one? For the latter you can just use a checkbox with the Appearance set to Button and Checked=true. This will make the checkbox appear like a button which is clicked.
If it is a custom requirement i.e. the button you need does not exist in the regular controls, I suggest you create a custom control button for your needs. Here is a link of a tutorial to create a custom control : How to: Create a Custom Image Button Control
You can also use a third party control like : Telerik Button - Radios and Checkboxes
Once the files are available to your site, activating the script is very easy:
...
$(document).ready(function() {
$(':checkbox').iphoneStyle();
});
You can change button's background image or background color in button click event handler.
Decalre somewhere in your code :
bool isClicked = false;
In event handler you can do :
private void button1_click(object sender, EventArgs e)
{
Button btn = sender as Button;
isClicked = !isClicked;
btn.BackgroundImage = isClicked? image1 : image2; // or use BackColor
}
There is a better and elegant solution. You can take a look how .NET draws it itself and try to do the same.
You should basically use
System.Windows.Forms.ButtonRenderer
class for drawing buttons in different states (Pressed, Hover etc.)
Please try to avoid using images for displaying states because to do it correctly, you would need to support different DPIs, sizing, proportions and so on. Rely on standard Render* classes fist.
is there a way where I can show an aspx form without using javascript?
Is there like this code in a asp button?
protected void btnLookUpPayment_Click(object sender, ImageClickEventArgs e)
{
webLookUpPayment wblp = new webLookUpPayment();
wblp.ShowModalDialog();
}
Because using a javascript popup modal is actually not my option, I have a gridview in my modal and upon clicking a row in that gridview, i will populate another gridview in another form, I can't explain it thoroughly because it is confusing, just want to know if there is a way where I can show a modal without using any javascript?
Thanks in advance for your help guys!
It will perfectly work. For pop up new .aspx from code behind
Response.Write("<script>window.open('About.aspx', 'hello', 'width=700,height=400,scrollbars=yes');</script>");
And for new window without pop up
ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", String.Format("<script>window.open('{0}');</script>", "About.aspx"));
mark it as answer if it works. Thanks
I have some buttons on a web form in my ASP.NET project. The end user has to interact with these buttons like you would with a calculator. My issue is that ever time the end user clicks a button the page is refreshed because of postback. I tried to turn postback off like so:
if (!Page.IsPostBack)
{
protected void btn7_Click(object sender, EventArgs e)
{
const string stringNumber7 = "7";
var text = txtNumber.Text;
text += stringNumber7;
txtNumber.Text = text;
CheckMaxLength();
}
}
But then the click event will not fire. I have tried using images, image buttons, image maps. I can't get the result I want from those object either. I would like to be able to stop postback, but still have my button click event to fire like the would in a windows app. I have see some forums talking using a update panel. I am not sure how to implement an update panel correctly. I am not familiar with AJAX controls.
Does anyone know how I can accomplish want I want to do using an update panel? Or how to stop postback and still fire server side code?
If the botton is invoking local / client side JavaScript, return false within the control event attribute which will cancel the PostBack.
<button onclick="MyMethod();return false;">Click Me</button>
of if you are using a server side control:
<asp:button runat="server" OnClientClick="MyMethod();return false;" />
I have a WebBrowser control hosted in a windows Form. The control is used to display hyperlinks which get created at runtime. These links point to some HTML pages and PDF documents.
The problem is that when the form hosting the browser control is loaded, the focus is on the form. When the TAB key is pressed, the focus does not shift to the first hyperlink. However, if I perform a mouse click on the control and then hit the TAB key, the tab focus is now on the first hyper link. I tried using Select() on the WebBrowser control and then I called Focus(), but it doesn't solve the problem.
Any ideas on how to set the tab focus on the first hyperlink at load? Thanks.
Cheers,
Harish
I guess it might be because the focus is set before the page is fully loaded. Try this:
private void Go(string url)
{
webBrowser1.Navigate(url);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Body.Focus();
}
You could also automatically select the focus on the first link directly by getting the HtmlElement of that first link.
If the above doesn't work, you might want to check other parts of your code to see if anything else is capturing the focus. Try searching for Select, Focus and ActiveControl in your code.
Use form.ShowDialog(form) instead on form.Show(), then it will work !
where form is the running instance of your windows Form
This is my solution
private void txtAdres_KeyPress(object sender, KeyPressEventArgs e)
{
int licznik = 1;
if (e.KeyChar == (char)13)
{
string adres = txtAdres.Text;
webBrowser1.Navigate(adres);
licznik = 0;
}
if (licznik == 0)
{
webBrowser1.Focus();
}
}
In a normal scenario it should be sufficient for you to set the TabIndex of the WebBrowser control to zero. This way, when the form loads the control will be focused and pressing TAB will iterate through the links.
Note that you should also change the TabIndex of the other controls on the form.
If this does not solve your problem, you need to add more detail on the complexity of the form hosting the control.