How to generate buttons dynamically - c#

I have one table with some records. My table like this
WFID clientID WorkflowName workflowsteps completedstep
12 15 print cutting,printing,lamination -
Workflowsteps will vary depending upon the workflow name.
In completedstep column it will show the completed steps. For example: if cutting and printing is done then it will show cutting,printing
Now I want to create dynamic buttons with the name cutting, printing, lamination
All the button will be disable by default only first button will be enable and clickable if I press first button "cutting" then its color should changed to red and The next "printing" button will be enable. Same process will repeat for each dynamic button.
How to do this in ASP.net?
:)

Put cutting button inside completedstep column.Do your code in gridviewrowcreated event, and enable only first button.Keep a printing button their also after cutting button make it visible false.Create a cuttingbuttonclick event handler method to handle visibility of printing button.
For dynamic button place a panel or placeholder inside grid.Then create button from codebehind and add it to the panel or placeholder.
Put this code inside gridviewrowcreated event.
Panel panel1=(Panel)e.Row.FindControl("PanelinsideGrid");
Button dynbtn = new Button();
dynbtn.Text = "Button Name";
panel1.Controls.Add(dynbtn)

Related

Visual C# Designating a Windows Forms LABEL as the Accept Button

I try to Designate the Accept Button property from my form to the click event of a label. If I would have used a button this wouldn't have been a problem but I have chosen to use a label for UI reasons.
Unfortunaly the Accept Button property only accept a button, so I have already tried to place a button on my form, make this button the acceptbutton and call the label_Click method when the button click_event is fired.
This worked like a charm but when I made the visibility property of my button false or made my button Hide() after the InitializeComponent() the Accept Button didn't worked anymore.
How Can the Accept Button property accept a label OR how can I visually hide a button without changing its visibility property?
Edit: a visualisation of what I tried to acomplish.
When the enter is pressed on the form (Accept Button property), I want to invoke the same method when the Play label is clicked.
To make the button "disappear" without hiding it you can change the border to 0, change the background color to the same color as the form and for FlatStyle property choose Flat. You could also use an image for the button background that is the same color as your form.

Control default action in ASP on Enter

This may be an easy question for you guys.
I have a web form with several buttons and only one textbox. When I enter a value in the textbox and press enter the method gets executed that is wired to the first top left button. I need to control what button's method gets executed (in this case it is a button in a whole different location that does db query).
I tried to alter tab index to have my desired button the lowest and I tried to pass focus to my desired button on page_load (like I would have done in Win Forms) but still if I enter text in textbox and hit eneter, the top left button's method gets executed.
I could put conditions in execution of top left button's method but that would be a workaround not a solution. So how do I control that behavior?
ASP.NET form has a defaultbutton property that specifies which button is clicked when ENTER is pressed. Just specify your button ID there. E.g.
<form id="form1" runat="server" defaultbutton="MyDbQueryButton">

c# application with on-screen keyboard

I'm making a Windows form application in c# and im creating on-screen keyboard for this application and i have some problems with that, because I don't know how to do few things.
What i have
Form1 with few textboxes and few richtextboxes.
panel1 with richtextbox and 5 buttons (A, B, C, DEL, ENTER).
What I want?
Everytime I click on any textbox or any richtextbox I want panel1 to show up.
I want the text from the textbox i have clicked to be displayed in a richtextbox on panel1.
When I click "ENTER" button on panel1 I want the text from richtextbox on panel1 to be transferred to textbox i have clicked before. (and ofcourse panel1 would hide after that).
I already made panel1 to show up when I click on textbox or richtextbox (I've used "Enter" event) and panel1 will hide when I click "ENTER" button on it. Is there maybe any other way to show panel1 everytime I click on textbox or richtextbox without coding "Enter" event for each one?
Now the hardest part is transferring text from form to panel and vice versa. To transfer text from the clicked textbox I've simply added a line of code to "Enter" event:
textBox1.Text = richTextBox1.Text;
Transferring text from richtextbox1 back to textbox is my main problem... I have solution for that but im looking for a correct and simple one... my solution is too noobish and complicated...
Will explain here what im looking for:
For example if int can remember number and string can remember text. I want something which can remember which textbox i've last clicked. I hope u can understand what I mean.
My english is not my main language so please reply if u cant understand anything and i will try my best to explain.
Thanks everyone for your time.
I would do these:
Create a base user control that derives from Textbox (if you'll be using only textboxes) or from a Control if there will be more than the textboxes used.
Handle the "Enter" event just as you do now in that base class.
Create the class that will derive from the EventArgs class and that will store a value of yout control. Let's call it "TextboxArgs" for now.
In the base user control, create an event and raise it in the "Enter" handler that you have and use a "TextboxArgs" class form step 3 to pass the text as the event argument.
Subscribe to this event in your panel so it will react properly.
Now, just use this base user control that you have for each textbox and it will raise an event and pass it's value as an argument. Panel will respond to it. If you do it that way then you won't need any additional coding no matter how many textboxes you add.

Load Multiple UpdatePanel Controls With JavaScript Button Clicks

I have 3 update panels on a page. Each of them is set to conditionally update. In each update panel I have a single button control that when clicked will populate the panel with data. Each panel is independent of one another.
Everything is working fine when you manually click each one of the 3 buttons in their respective panel. The issue I am having comes up when I use JavaScript to click the buttons. I have success when executing a single JavaScript call but when I try to click all 3 buttons with JavaScript, things behave sporadically. Depending on where I place the JavaScript calls in my code, different panels work and the others do not.
For example:
__doPostBack('btnBindTeamTicketList', '');
__doPostBack('btnBindPriorityList', '');
__doPostBack('btnSearchTemplate', '');
will show the panel that holds the 'btnSearchTemplate' button, but not the others. Different results occur when I change the sequence around.
Is there a way to click my 3 independent buttons (each in its respective panel) using JavaScript so that each panel will load as if I were clicking on them individually? I am guessing this has to do with the AJAX somehow conflicting with each other or a timing problem. Anyone point me in the right direction?
I am using ASP.NET 3.5/C#
I think you should do one postback. Put a hidden update panel in your page and put a button inside this new update panel. This button should call events
btnBindTeamTicketList_Click(null, null)
btnBindPriorityList_Click(null, null)
btnSearchTemplate_Click(null, null)
and should update the other update panels like upTeamTicketList.Update(). Now try clicking this new button.

Preventing a button from responding to 'Enter' in ASP.net

I have a master template that all the pages on my site use. In the template there is an empty panel. In the code-behind for the page an imagebutton is created in the panel dynamically in my Page_Load section (makes a call to the DB to determine which button should appear via my controller).
On some pages that use this template and have forms on them, pressing the Enter key fires the click event on this imagebutton rather than the submit button in the form. Is there a simple way to prevent the imagebutton click event from firing unless it's clicked by the mouse? I'm thinking a javascript method is a hack, especially since the button doesn't even exist in the master template until the button is dynamically created on Page_Load (this is ugly since I can't simply do <% =btnName.ClientId %> to refer to the button's name in my aspx page).
I tried setting a super-high tabindex for the image button and that did nothing. Also set the button to be the DefaultButton in its panel on the master template but that did not work either. Moreover, I don't want to add a property to all of my pages that use this template (there are hundreds). It would be optimal to find a solution that works globally from my master template.
I'll try to show our example here:
We have a button on the top of each page in our system that lets you star the page as one of your favorites, sort of a server-side bookmark system. When the page loads it looks to see if the page is one of your favorites or not and then shows a gold star if it is, and a gray star if it is not. Clicking the imagebutton of a star toggles the page favorite status.
In my master template (FullMenu.master) I have this panel
<asp:Panel runat="server" ID="pnlFavorite" style="display:inline;"></asp:Panel>
Next there is a class which creates the button and adds it to the panel on the master template:
public void InsertStarButton()
{
CreateStarButton();
pnl.Controls.Add(bright);
}
and
private void CreateStarButton()
{
bright = new ImageButton();
bright.ImageUrl = "~/resources/images/star.png";
bright.Height = new Unit(12, UnitType.Pixel);
bright.ID = "btnStar";
}
What I tried earlier, that didn't work, was in InsertStarButton() I added a line pnl.DefaultButton = "btnStar" but that didn't change anything on the page. Even if I had the cursor blinking inside a text box in the form on the page the star button would fire its click event if the Enter key was pressed.
http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx
Pressing ENTER on a single-line textbox on a form will submit the form. That's how it works.

Categories

Resources