One at a time C++ win 32 - win32gui

My question is : In win32 I send messages to the textbox with (for example, a sample of my code)
SendMessage(TextBox,EM_SETSEL,-1,-1); //no difference between passing 0 or -1
SendMessage(TextBox,EM_REPLACESEL,TRUE,(LPARAM)buf2);
//SendDlgItemMessage(TextBox, IDC_PLAYERLIST, LB_RESETCONTENT, 0, 0);
//hwnd.refresh();
SetWindowText( GetDlgItem( TextBox, IDC_EDIT ), "" );
But it doesnt clear the textbox.
So how do i clear the textbox so i can output another question that i would like to ask the user?
For knowledge, I develop a software in which people are asked different things , therefore i need step by step to appear the questions not all at the same time.

Assuming TextBox is the HWND of your actual edit control, and not its parent dialog, than replace
SetWindowText( GetDlgItem( TextBox, IDC_EDIT ), "" );
With
SetWindowText( TextBox, "" );

Related

How to validate TextBox?

I have a textbox for a zipcode in which i hav made a validation that the user cannot enter number less then or more then 6, but even if user enters 3 nos it is working.SO i want an error msg to display if user enters something wrong
Private Shared Function ValidateZip(ByVal pintZip As String, ByRef pobjErrMsg As Common.ErrorMessage) As Boolean
If pintZip.Length <> 6 Then
ElseIf IsNumeric(pintZip) Then
End If
Return True
End Function
You have no code in either the If or ElseIf blocks and you are always returning True
Private Shared Function ValidateZip(ByVal pintZip As String, ByRef pobjErrMsg As Common.ErrorMessage) As Boolean
If pintZip.Length <> 6 Then
MsgBox("Zip code should have 6 characters")
pintZip.Focus
Return False
ElseIf IsNumeric(pintZip) Then
MsgBox("Congratulations, you have entered right Zip code")
Return True
End If
End Function
Try like this
UPDATE #1
Seems like you are using ASP.net not VB.net, here is the answer:
You can't show dialog box ON SERVER from ASP.NET application, it makes no sense since your user is using browser and it can't see message boxes on server. You have to understand how web sites work, server side code (ASP.NET in your case) produces html, javascript etc on server and then browser loads that content and displays it to the user, so in order to present modal message box to the user you have to use Javascript, for example alert function.
Here is the example for asp.net :
example
SOURCE

Blackberry 10 SystemPrompt->inputField does not change value on user input

I need to display system input dialog: title, some text, input field, OK & Cancel buttons.
I'm new to BB development, so I carefully read docs and samples: http://developer.blackberry.com/native/documentation/cascades/ui/dialogs_toasts/prompts.html
and write the same code (let's say doc author cheated a bit in the most important part - not covering obtaining of user input with non-compiling source code - "qDebug() << "Prompt Accepted:" << text;").
void MainPage::showPrompt() {
SystemPrompt *dialog = new SystemPrompt();
dialog->inputField()->setDefaultText("TEST");
QObject::connect(dialog, SIGNAL(finished(bb::system::SystemUiResult::Type)),
this, SLOT(promptHandler(bb::system::SystemUiResult::Type)));
dialog->show();
}
void MainPage::promptHandler(bb::system::SystemUiResult::Type value) {
if (value == SystemUiResult::ConfirmButtonSelection) {
SystemPrompt *dialog = (SystemPrompt *)QObject::sender();
qDebug("text is: '%s'", qPrintable(dialog->inputField()->defaultText()));
}
}
Regardless of user input on device/simulator, inputField()->defaultText() value is always "TEST" as it was initialized.
How do I get the user input here? dialog->exec() does not change anything.
PS. Expert level question: And how do I allow empty input in SystemPrompt dialog (by default "OK" button becomes disabled on empty input).
Shame upon me. I did not read documentation carefully.
->inputFieldTextEntry() does contain the user input.
PS. First time I see such sophisticated logic of handling such simple thing as user input in text edit...

How do I Reset the Values in My ASP.NET Fields?

The current form is here. It is not complete, and only a couple options will work.
Select "Image CD" and then any resolution and click "Add to Order." The order will be recorded on the server-side, but on the client-side I need to reset the product drop-down to "{select}" so that the user will know that they need to select another product. This is consistant with the idea that the sub-selections disappear.
I don't know whether I should be using ASP postback or standard form submittal, and most of the fields need to be reset when the user adds an item to the order.
I'd use Response.Redirect(Request.RawUrl) method to reset the form data from the server side.
A little explanation: this is PRG design pattern
Used to help avoid certain duplicate
form submissions and allow user agents
to behave more intuitively with
bookmarks and the refresh button.
A workaround for this question:
necessary data may be stored in Session for example. This means we getting the data with the first POST, putting it to the storage, performing redirect and getting it back.
In the pageload event on the form, you need to add something simalar to this:
if (IsPostBack)
{
//Proccess the order here
ProductOption.SelectedIndex = 0;
}
That will allow you to process the order, but then start over the order form.
The simplest means would be a recursive function that forks on the type of control
private void ResetControls( Control control )
{
if ( control == null)
return;
var textbox = control As TextBox;
if ( textbox != null )
textbox.Text = string.Empty;
var dropdownlist = control as DropDownList;
if ( dropdownlist != null )
dropdownlist.SelectedIndex = 0; // or -1
...
foreach( var childControl in controlControls )
ResetControls( childControl );
}
You would this call this function in your Load event by passing this. (This is presuming you want to reset more than a single control or small list of controls).

Force ASP.NET textbox to display currency with $ sign

Is there a way to get an ASP.NET textbox to accept only currency values, and when the control is validated, insert a $ sign beforehand?
Examples:
10.23 becomes $10.23
$1.45 stays $1.45
10.a raises error due to not being a valid number
I have a RegularExpressionValidator that is verifying the number is valid, but I don't know how to force the $ sign into the text. I suspect JavaScript might work, but was wondering if there was another way to do this.
The ASP.NET MaskedEdit control from the AJAX Control Toolkit can accomplish what you're asking for.
I know an answer has already been accepted, but I wanted to throw out another solution for anyone with the same problem and looking for multiple workarounds.
The way I do this is to use jQuery format currency plugin to bind user input on the client side. Parsing this input on the server side only requires:
// directive
using System.Globalization;
// code
decimal input = -1;
if (decimal.TryParse(txtUserInput.Text, NumberStyles.Currency,
CultureInfo.InvariantCulture, out input))
{
parameter = input.ToString();
}
The only downfall to this is that the user can have javascript turned off, in which case the RegEx validator running server-side would work as a fall-back. If the control is databound, all you have to do is decimalValue.ToString("{0:c}") , as mentioned by others, in order to display the proper currency formatting.
The cool thing about this is that if the user enters the textbox and it shows $0.00 on the client side, the server-side if statement would return false. If your decimal value isn't nullable in the database, just change decimal input = -1 to decimal input = 0 and you'll have a default value of 0.
Another way to do this might be to place the dollar sign outside to the left of the text box. Is there a real need to have the dollar sign inside of the box or will a simple label do?
decimal sValue = decimal.Parse(txtboxValue.Text.Trim());
// Put Code to check whether the $ sign already exist or not.
//Try making a function returning boolean
//if Dollar sign not available do this
{ string LableText = string.Format("{0:c}", sValue); }
else
{ string LableText = Convert.ToString(sValue); }
string sValue = Convert.ToString(txtboxValue.Text.Trim());
// Put Code to check whether the $ sign already exist or not.
//Try making a function returning boolean
//if Dollar sign not available do this
{ string LableText = string.Format("{0:c}", "sValue"); }
else
{ string LableText = Convert.ToString(sValue); }
In the .CS you could do a pattern match along the lines of,
string value = text_box_to_validate.Text;
string myPattern = #"^\$(\d{1,3},?(\d{3},?)*\d{3}(\.\d{0,2})|\d{1,3}(\.\d{2})|\.\d{2})$";
Regex r = new Regex(myPattern);
Match m = r.Match(value);
if (m.Success)
{
//do something -- everything passed
}
else
{
//did not match
//could check if number is good, but is just missing $ in front
}

ASP.NET paging control [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm looking for a decent paging control in ASP.NET, much like the Stackoverflow pager. Can anyone recommend one?
I'd prefer one that didn't use Postback either, just a customisable querystring.
It's quite easy to roll your own. I created a simple user control based on the stack overflow pager with two properties...
Total number of pages available according to the underlying data
Number of links to show
The selected page is determined by reading the query string. The biggest challenge was altering the URL with the new page number. This method uses a query string parameter 'p' to specify which page to display...
string getLink(int toPage)
{
NameValueCollection query = HttpUtility.ParseQueryString(Request.Url.Query);
query["p"] = toPage.ToString();
string url = Request.Path;
for(int i = 0; i < query.Count; i++)
{
url += string.Format("{0}{1}={2}",
i == 0 ? "?" : "&",
query.Keys[i],
string.Join(",", query.GetValues(i)));
}
return url;
}
A simple formula to determine the range of page numbers to show...
int min = Math.Min(Math.Max(0, Selected - (PageLinksToShow / 2)), Math.Max(0, PageCount - PageLinksToShow + 1));
int max = Math.Min(PageCount, min + PageLinksToShow);
Each link then gets generated using something like (where min and max specify the range of page links to create)...
for (int i = min; i <= max; i++)
{
HyperLink btn = new HyperLink();
btn.Text = (i + 1).ToString();
btn.NavigateUrl = getLink(i);
btn.CssClass = "pageNumbers" + (Selected == i ? " current" : string.Empty);
this.Controls.Add(btn);
}
One can also create 'Previous' (and 'Next') buttons...
HyperLink previous = new HyperLink();
previous.Text = "Previous";
previous.NavigateUrl = getLink(Selected - 1);
The first and last buttons are straight forward...
HyperLink previous = new HyperLink();
previous.Text = "1";
first.NavigateUrl = getLink(0);
In determining when to show the "...", show a literal control when the link range is not next to the first or last pages...
if (min > 0)
{
Literal spacer = new Literal();
spacer.Text = "…";
this.Controls.Add(spacer);
}
Do the same for above for "max < PageCount".
All of this code is put in an override method of CreateChildControls.
I was expecting more answers but it looks like a lot of people just make their own. I've found a decent one that is maintained quite often on codeproject.com
It's not quite the same as the stackoverflow.com one. It'd be nice if there was a decent open source control that had a variety of different output options.
I've worked with the DevExpress and Telerik page controls and prefer the DevExpress pager. I'm not sure if the DevExpress pager can work directly with a querystring but I would be surprised if it didn't as it is very flexible. As far as paging between existing pages after download, everything can reside on the client or, if a trip to the server is necessary, the control is fully AJAX equipped. I suggest you start your search at www.devexpress.com and then check out www.Telerik.com as well (which is also AJAX equipped).
Not a control, but this is the way to implement paging at the DB level: SQL Server 2005 Paging
I have written a pager control named: Flexy Pager
Read more: http://www.codeproject.com/Articles/748270/Flexy-Pager-for-ASP-NET-WebForm-MVC
You can try NPager. Uses query string for page indexes, no postbacks. Needs Bootstrap for styling, however you can have your own custom css classes for the control using 'pagination' CSS class.Here is a working DEMO

Resources